nexus_1975
Newbie
I am using PIC16F76 I am trying to write my own code.
When I use the following code it compiles and runs on hardware with 1 error.
If RC4_bit == 0 and i == 10 program will work well since 2nd iteration, i want it work with 1st iteration.
ChecFunc( ) not working during 1st iteration!
Added code tags
When I use the following code it compiles and runs on hardware with 1 error.
If RC4_bit == 0 and i == 10 program will work well since 2nd iteration, i want it work with 1st iteration.
ChecFunc( ) not working during 1st iteration!
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 /* * Test configuration: MCU: PIC16F76 */ unsigned int i, count, cnt, time_in_ms; void Vdelay_ms(time_in_ms); CheckFunc(time_in_ms); CheckFunc(time_in_ms) { if((RC4_bit == 0) && (i == 10)) //continue; { i=0; PORTA = 0x00; time_in_ms = 150;//continue; } else if((RC3_bit == 0) && (i == 20)) //continue; { i=0; PORTA = 0x00; time_in_ms = 150;//continue; } else if(RC2_bit == 0) { time_in_ms = 120; //continue; } else if(RC1_bit == 0) { time_in_ms = 200;//continue; } else if(RC0_bit == 0) { time_in_ms = 1000; //continue; } else if(PORTC == 0xFF) { time_in_ms = 500; //continue; } return time_in_ms; } void main() { // // initialize system // ADCON0 = 0; ADCON1 = 0x07; // all digital port pins TRISC = 0xFF; // port C, bit 1, is input TRISB = 0x00; // port B, bit 0, is output TRISA = 0x00; // port A is output PORTC = 0xFF; PORTB = 0x00; // all LEDs on PORTA = 0x00; cnt = 0; // Initialize cnt INTCON = 0x00; // Set GIE, PEIE time_in_ms = 150; // start count at zero while ( 1 ) // the one and only program loop { for(count=0;count<=7;count++) { PORTB = 0x10; CheckFunc(); Vdelay_ms(time_in_ms); /* One second pause */ PORTB = 0x01; CheckFunc(); Vdelay_ms(time_in_ms); /* One second pause */ PORTB = 0x02; CheckFunc(); Vdelay_ms(time_in_ms); /* One second pause */ PORTB = 0x04; CheckFunc(); Vdelay_ms(time_in_ms); /* One second pause */ PORTB = 0x08; CheckFunc(); Vdelay_ms(time_in_ms); /* One second pause */ PORTA = PORTA++; // i=i+5; } PORTA = 0x00; PORTB = 0x00; count=0; i=0; } }
Last edited by a moderator: