xinhui
Junior Member level 1
i had met some problem in my coding. hope someone can help me solve the problem.
here is how my system work:
1. when button is pressed, the 2nd "if" will function.
2. when button is not pressed, the 1st "if" will function and stop after PORTC=0.
now the problem is when the system's button in "not pressed" condition, the circuit will run and work as what i want, but when i pressed the button after that, the circuit will not function as what i want, and it will function properly as i pressed the reset button in PIC16F877A. is that got some mistake in my coding? here is my code:
hope someone can help me solve this problem...:grin:
here is how my system work:
1. when button is pressed, the 2nd "if" will function.
2. when button is not pressed, the 1st "if" will function and stop after PORTC=0.
now the problem is when the system's button in "not pressed" condition, the circuit will run and work as what i want, but when i pressed the button after that, the circuit will not function as what i want, and it will function properly as i pressed the reset button in PIC16F877A. is that got some mistake in my coding? here is my code:
Code:
#define button PORTA.F4
#define LEDs PORTA.F0
#define Buzzer PORTA.F0
#define STEP1 0b00010010
#define STEP2 0b00000010
#define STEP3 0b00000110
#define STEP4 0b00000100
#define STEP5 0b00001100
#define STEP6 0b00001000
#define STEP7 0b00011000
#define STEP8 0b00010000
void Delay(unsigned int ms)
{
switch(ms)
{
case 500:
Delay_ms(500);
break;
case 200:
Delay_ms(200);
break;
default:
Delay_ms(1000);
}
}
void main(void)
{ unsigned int i;
TRISA =0b00110000;
TRISB = 0; //Port B as output (LCD is OUTPUT)
TRISC=0*00;
PORTC=0;
Lcd_Init(&PORTB);
Lcd_Config(&PORTB,3,1,2,7,6,5,4);
Lcd_Cmd(LCD_CURSOR_OFF);
while(1){
if(button==1)
{ //Button is not pressed
Lcd_Cmd(LCD_CLEAR); //Clear LCD display (Blank the LCD screen)
Lcd_Out(1, 4, "HAVE A SAFE"); //Print text on LCD at line 1, column 4
Lcd_Out(2, 6, "JOURNEY"); //Print text on LCD at line 2, column 5
Delay_ms(1000);
LEDs=0;
PORTC=STEP8;
Delay(200);
PORTC=STEP7;
Delay(200);
PORTC=STEP6;
Delay(200);
PORTD=STEP5;
Delay(200);
PORTC=STEP4;
Delay(200);
PORTC=STEP3;
Delay(200);
PORTC=STEP2;
Delay(200);
PORTC=STEP1;
Delay(200);
break;
}
if(button==0)//Button is pressed
{
Lcd_Cmd(LCD_CLEAR); //Clear LCD display (Blank the LCD screen)
Lcd_Out(1,5,"CAUTION!!!");
Lcd_Out(2,5,"CAUTION!!!");
Delay_ms(500);
PORTC=STEP1;
Delay(500);
PORTC=STEP2;
Delay(500);
PORTC=STEP3;
Delay(500);
PORTC=STEP4;
Delay(500);
PORTC=STEP5;
Delay(500);
PORTC=STEP6;
Delay(500);
PORTC=STEP7;
Delay(500);
PORTC=STEP8;
Delay(500);
while(1){
Buzzer=1;
Delay_ms(2000);
LEDs=1;
Delay_ms(2000);
LEDs=0;
Delay_ms(500); }
break;
}
}
}
hope someone can help me solve this problem...:grin: