asking
Full Member level 5
- Joined
- Sep 21, 2010
- Messages
- 279
- Helped
- 6
- Reputation
- 12
- Reaction score
- 6
- Trophy points
- 1,298
- Activity points
- 3,377
#define MX_PIC
//Defines for microcontroller
#define P18F4520
#define MX_EE
#define MX_EE_TYPE3
#define MX_EE_SIZE 256
#define MX_SPI
#define MX_SPI_C
#define MX_SPI_SDI 4
#define MX_SPI_SDO 5
#define MX_SPI_SCK 3
#define MX_UART
#define MX_UART_C
#define MX_UART_TX 6
#define MX_UART_RX 7
#define MX_I2C
#define MX_MI2C
#define MX_I2C_C
#define MX_I2C_SDA 4
#define MX_I2C_SCL 3
#define MX_PWM
#define MX_PWM_CNT 2
#define MX_PWM_TRIS1 trisc
#define MX_PWM_1 2
#define MX_PWM_TRIS2 trisc
#define MX_PWM_2 1
#define MX_PWM_TRIS2a trisb
#define MX_PWM_2a 3
//Functions
#define MX_CLK_SPEED 19660800
#ifdef _BOOSTC
#include <system.h>
#endif
#ifdef HI_TECH_C
#include <pic18.h>
#endif
//Configuration data
#ifdef _BOOSTC
#pragma DATA 0x300000, 0xff
#endif
#ifdef _HI_TECH_C
%C__CONFIG(%A, %V);
#endif
#ifdef _BOOSTC
#pragma DATA 0x300001, 0x8
#endif
#ifdef _HI_TECH_C
%C__CONFIG(%A, %V);
#endif
#ifdef _BOOSTC
#pragma DATA 0x300002, 0x1f
#endif
#ifdef _HI_TECH_C
%C__CONFIG(%A, %V);
#endif
#ifdef _BOOSTC
#pragma DATA 0x300003, 0x1e
#endif
#ifdef _HI_TECH_C
%C__CONFIG(%A, %V);
#endif
#ifdef _BOOSTC
#pragma DATA 0x300004, 0xff
#endif
#ifdef _HI_TECH_C
%C__CONFIG(%A, %V);
#endif
#ifdef _BOOSTC
#pragma DATA 0x300005, 0x81
#endif
#ifdef _HI_TECH_C
%C__CONFIG(%A, %V);
#endif
#ifdef _BOOSTC
#pragma DATA 0x300006, 0x81
#endif
#ifdef _HI_TECH_C
%C__CONFIG(%A, %V);
#endif
#ifdef _BOOSTC
#pragma DATA 0x300007, 0xff
#endif
#ifdef _HI_TECH_C
%C__CONFIG(%A, %V);
#endif
#ifdef _BOOSTC
#pragma DATA 0x300008, 0xf
#endif
#ifdef _HI_TECH_C
%C__CONFIG(%A, %V);
#endif
#ifdef _BOOSTC
#pragma DATA 0x300009, 0xc0
#endif
#ifdef _HI_TECH_C
%C__CONFIG(%A, %V);
#endif
#ifdef _BOOSTC
#pragma DATA 0x30000a, 0xf
#endif
#ifdef _HI_TECH_C
%C__CONFIG(%A, %V);
#endif
#ifdef _BOOSTC
#pragma DATA 0x30000b, 0xe0
#endif
#ifdef _HI_TECH_C
%C__CONFIG(%A, %V);
#endif
#ifdef _BOOSTC
#pragma DATA 0x30000c, 0xf
#endif
#ifdef _HI_TECH_C
%C__CONFIG(%A, %V);
#endif
#ifdef _BOOSTC
#pragma DATA 0x30000d, 0x40
#endif
#ifdef _HI_TECH_C
%C__CONFIG(%A, %V);
#endif
//Internal functions
#include "C:\Program Files (x86)\Matrix Multimedia\Flowcode V4\FCD\internals.h"
//Macro function declarations
//Variable declarations
#define FCSZ_S 20
char FCV_I;
char FCV_J;
short FCV_N;
char FCV_A;
char FCV_S[FCSZ_S];
//Macro implementations
void main()
{
//Initialisation
adcon1 = 0x0F;
//Interrupt initialisation code
//Loop
//Loop: While 1
while (1)
{
//Input
//Input: A0 -> N
trisa = trisa | 0x01;
FCV_N = ((porta & 0x01) == 0x01);
//Decision
//Decision: N==1?
if (FCV_N==1)
{
//Output
//Output: N -> B7
trisb = trisb & 0x7f;
if (FCV_N)
portb = (portb & 0x7f) | 0x80;
else
portb = portb & 0x7f;
} else {
//Output
//Output: 0 -> B7
trisb = trisb & 0x7f;
if (0)
portb = (portb & 0x7f) | 0x80;
else
portb = portb & 0x7f;
}
}
}
sbit LED at RC0_bit;
sbit Switch at RC1_bit;
#define Switch_Pin 1
#define Switch_Port PORTC
#define Debounce_Time 20
void main() {
ANSEL = 0b00000000; //All I/O pins are configured as digital
CMCON0 = 0x07 ; // Disbale comparators
TRISC = 0b00000000; // PORTC All Outputs
TRISA = 0b00001000; // PORTA All Outputs, Except RA3
LED = 0;
do {
if (Button(&Switch_Port, Switch_Pin, Debounce_Time, 0)) {
if (!Switch) {
LED = ~LED;
}
while (!Switch); // Wait for release of the button
}
} while(1); // Infinite Loop
}
HTML:sbit LED at RC0_bit; sbit Switch at RC1_bit; #define Switch_Pin 1 #define Switch_Port PORTC #define Debounce_Time 20 void main() { ANSEL = 0b00000000; //All I/O pins are configured as digital CMCON0 = 0x07 ; // Disbale comparators TRISC = 0b00000000; // PORTC All Outputs TRISA = 0b00001000; // PORTA All Outputs, Except RA3 LED = 0; do { if (Button(&Switch_Port, Switch_Pin, Debounce_Time, 0)) { if (!Switch) { LED = ~LED; } while (!Switch); // Wait for release of the button } } while(1); // Infinite Loop }
[syntax=c]
void main() {
TRISA.F0 = 0x01;
PORTA = 0x00;
TRISB.F0 = 0x00;
PORTB = 0x00;
while(1) {
if(PORTA.F0 == 1) PORTB.F0 = ~PORTB.F0;
}
} [/syntax]
Simple Code is
Code:[syntax=c] void main() { TRISA.F0 = 0x01; PORTA = 0x00; TRISB.F0 = 0x00; PORTB = 0x00; while(1) { if(PORTA.F0 == 1) PORTB.F0 = ~PORTB.F0; } } [/syntax]
if(PORTA.F0 == 1) LED = ~LED;
post your full code.
void main()
{
void Soft_I2C_Init();
ADCON1 = 0xFF;
TRISB = 0x00; // Set PORTB7 input all other direction to be output
PORTB = 0xff; // Turn OFF LEDs on PORTB
TRISA = 0b110000; // RA5-6-7 is input only
TRISC = 0b00001100; // RA5-6-7 is input only
write_ds1307(0,0x00);
do {
set = 0;
if(PORTC.F2 == 0)
{
delay_ms(70);
if(PORTC.F2 == 0)
{
set_count++;
if(set_count >= 3)
{
set_count = 0;
}
}
}
if(set_count)
{
if(PORTC.F3 == 0)
{
if(PORTC.F3 == 0)
set = 1;
}
if(set_count && set)
{
switch(set_count)
{
case 1:
hour = BCD2Binary(hour);
hour = hour + set;
if(hour>=24)
hour=0;
hour = Binary2BCD(hour);
write_ds1307(2, hour); //write hour
break;
case 2:
minute = BCD2Binary(minute);
minute = minute + set;
if(minute >= 60)
minute = 0;
if(minute < 0)
minute = 59;
minute = Binary2BCD(minute);
write_ds1307(1, minute); //write min
break;
}
}
}
[syntax=c]
#define SW PORTA.F0
#define LED PORTB.F0
void main() {
TRISA.F0 = 0x01;
PORTA = 0x00;
TRISB.F0 = 0x00;
PORTB = 0x00;
while(1) {
if(SW == 1) {
Delay_ms(100)
if(SW == 1) {
LED = ~LED
}
}
}
}
[/syntax]
if(PORTC.F7 == 0)
{
Delay_ms(30);
if(PORTC.F7 == 0) {
LED = ~LED;
}
}
LED == 0 is not right. PORTC.F7 == 0 is right. LED is connected to output pin, so, LED = 0 makes sense.
[syntax=c] #define SW PORTA.F0
#define LED PORTB.F7
void main() {
TRISA.F0 = 0x01;
PORTA = 0x00;
TRISB.F7 = 0x00;
PORTB = 0x00;
while(1) {
if(SW == 1) {
Delay_ms(100)
if(SW == 1) {
LED = ~LED
}
}
}
} [/syntax]
[syntax=c]
#define SW PORTA.F0
#define LED PORTB.F7
void main() {
TRISA.F0 = 0x01;
PORTA = 0x00;
TRISB.F7 = 0x00;
PORTB = 0x00;
ANSEL = 0x00;
ANSELH = 0x00;
CM1CON0.C1ON = 0;
CM2CON0.C2ON = 0;
while(1) {
if(SW == 1) {
Delay_ms(150);
if(SW == 1) {
LED = ~LED;
}
}
}
}
[/syntax]
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?