Hey guys!
I was making a buzzer for a school quiz contest using AT89C52 microcontroller. It works such that any team can press and the order of press is shown on an LCD module. My code is below. In the keil simulation window, everything works as it should, however, in my breadboard setup, the lcd module just lights up and nothing else happens. It does not respond to the button presses. Could you please check the code?
I was making a buzzer for a school quiz contest using AT89C52 microcontroller. It works such that any team can press and the order of press is shown on an LCD module. My code is below. In the keil simulation window, everything works as it should, however, in my breadboard setup, the lcd module just lights up and nothing else happens. It does not respond to the button presses. Could you please check the code?
Rich (BB code):
#include <REGX52.H>
sbit rs = P3^5;
sbit rw = P3^6;
sbit en = P3^7;
int cnt = 0, counter = 1, flag1=0, flag2=0, flag3=0, flag4=0, flag5=0, flag6=0, flag7=0, flag8=0, team1, team2, team3, team4, team5, team6, team7, team8;
void buzzer(void);
void ISR_timer0(void) interrupt 1
{
cnt++;
TH0 = 0x6F;
TL0 = 0xFF;
if(cnt==1000)
{
P0_7 = 1;
TR0 = 0;
cnt = 0;
}
}
void delay()
{
TR0 = 0;
P0_7 = 0;
TMOD = 0x01;
TH0 = 0x6F;
TL0 = 0xFF;
IE = 0x82;
TR0 = 1;
}
void delay2(unsigned int m)
{
unsigned int i;
for(i=0;i<m;i++);
}
void lcmd(unsigned char cmd)
{
P2 = cmd;
rs = 0;
rw = 0;
en = 1;
delay2(1);
en = 0;
}
void ldata(unsigned char dat)
{
P2 = dat;
rs = 1;
rw = 0;
en = 1;
delay2(1);
en = 0;
}
void call()
{
P1 = 0xFF;
P3_1 = 1;
flag1=flag2=flag3=flag4=flag5=flag6=flag7=flag8=team1=team2=team3=team4=team5=team6=team7=team8=0;
counter = 1;
cnt = 0;
lcmd(0x38);
delay2(5);
lcmd(0x0E);
delay2(5);
lcmd(0x01);
delay2(5);
lcmd(0x80);
delay2(5);
buzzer();
}
void buzzer()
{
while(P3_1)
{
while(P1==0xFF);
if(P1_0 == 0)
{
P1_0 = 1;
if(flag1==0)
{flag1 = 1;
delay();
team1 = counter;
counter++;}
}
if(P1_1 == 0)
{
P1_1 = 1;
if(flag2==0){
flag2=1;
delay();
team2 = counter;
counter++;
}}
if(P1_2 == 0)
{
P1_2 = 1;
if(flag3==0){
flag3=1;
delay();
team3 = counter;
counter++;
}}
if(P1_3 == 0)
{
P1_3 = 1;
if(flag4==0){
flag4=1;
delay();
team4 = counter;
counter++;
}}
if(P1_4 == 0)
{
P1_4 = 1;
if(flag5==0){
flag5=1;
delay();
team5 = counter;
counter++;
}}
if(P1_5 == 0)
{
P1_5 = 1;
if(flag6==0){
flag6=1;
delay();
team6 = counter;
counter++;
}}
if(P1_6 == 0)
{
P1_6 = 1;
if(flag7==0){
flag7=1;
delay();
team7 = counter;
counter++;
}}
if(P1_7 == 0)
{
P1_7 = 1;
if(flag8==0){
flag8=1;
delay();
team8 = counter;
counter++;
}}
lcmd(0x01);
lcmd(0x80);
ldata('A');
ldata(team1);
ldata(' ');
ldata('B');
ldata(team2);
ldata(' ');
ldata('C');
ldata(team3);
ldata(' ');
ldata('D');
ldata(team4);
ldata(' ');
ldata('E');
ldata(team5);
ldata(' ');
ldata('F');
ldata(team6);
}
call();
}
void main()
{
lcmd(0x38);
delay2(5);
lcmd(0x0E);
delay2(5);
lcmd(0x01);
delay2(5);
lcmd(0x80);
delay2(5);
P3_1 = 1;
P1 = 0xFF;
buzzer();
}
Last edited by a moderator: