giúp mình sửa code c cho chương trình này với...chỉ mới làm quen... mong các bạn chỉ bảo...mình dịch thì ko thấy báo lỗi nhưng chạy debug thì bị lỗi..
#include <REGX51.H>
sbit ledD0=P0^0;
sbit ledD1=P0^1;
sbit ledD2=P0^2;
sbit ledD3=P0^3;
sbit ledD4=P0^4;
sbit ledD5=P0^5;
sbit ledD6=P0^6;
sbit LED_0=P2^0; //hang tram
sbit LED_1=P2^1; //hang chuc
sbit LED_2=P2^2; //hang don vi
sbit INTR_1=P3^2;
sbit INTR_2=P3^3;
sbit CS_1=P3^4;
sbit CS_2=P3^5;
long n;
int r,hangtram,hangchuc,hangdonvi;
void delay(long time)
{
for(n=0; n<time; n++)
{
;
}
}
void chuso()
{
int r,hangtram,hangchuc,hangdonvi;
hangtram=P1/100;
r=P1-100*hangtram;
hangchuc=r/10;
hangdonvi=r-hangchuc*10;
}
unsigned char x;
void Hienthiled(x) // Co 1 bien dau vao de xac dinh xem la hien thi so nao
{
switch(x)
{
case 0: { P0=0x40 ; break;} // So 0
case 1: { P0=0x79 ; break;}// So 1
case 2: { P0=0x24 ; break;}// So 2
case 3: { P0=0x30; break;}// So 3
case 4: { P0=0x19; break;}// so 4
case 5: { P0=0x12; break; }// so 5
case 6: { P0=0x2 ; break;} // So 6
case 7: { P0=0x78 ; break;}// So 7
case 8: { P0=0x0 ; break;}// So 8
case 9: { P0=0x10; break;}// So 9
}
}
void inhangtram()
{
LED_0=1;
LED_1=LED_2=0;
Hienthiled(hangtram);
}
void inhangchuc()
{
LED_1=1;
LED_0=LED_2=0;
Hienthiled(hangchuc);
}
void inhangdonvi()
{
LED_2=1;
LED_1=LED_0=0;
Hienthiled(hangdonvi);
}
void laymauADC1()
{
CS_1=0;
WR=1;
while (INTR_1==1);
CS_1=0;
RD=0;
}
void laymauADC2()
{
CS_2=0;
WR=1;
while (INTR_1==1);
CS_2=0;
RD=0;
}
void phiman()
{
if(P2_6==0)//phim1
{
INTR_1=1;
INTR_2=0;
laymauADC1();
}
if(P2_7==0)//phim2
{
INTR_1=0;
INTR_2=1;
laymauADC2();
}
}
void main(void)
{
{
phiman();
chuso();
inhangtram();
delay(1000);
inhangchuc();
delay(1000);
inhangdonvi();
delay(1000);
}
}
file mô phỏng có bên dưới!!!
#include <REGX51.H>
sbit ledD0=P0^0;
sbit ledD1=P0^1;
sbit ledD2=P0^2;
sbit ledD3=P0^3;
sbit ledD4=P0^4;
sbit ledD5=P0^5;
sbit ledD6=P0^6;
sbit LED_0=P2^0; //hang tram
sbit LED_1=P2^1; //hang chuc
sbit LED_2=P2^2; //hang don vi
sbit INTR_1=P3^2;
sbit INTR_2=P3^3;
sbit CS_1=P3^4;
sbit CS_2=P3^5;
long n;
int r,hangtram,hangchuc,hangdonvi;
void delay(long time)
{
for(n=0; n<time; n++)
{
;
}
}
void chuso()
{
int r,hangtram,hangchuc,hangdonvi;
hangtram=P1/100;
r=P1-100*hangtram;
hangchuc=r/10;
hangdonvi=r-hangchuc*10;
}
unsigned char x;
void Hienthiled(x) // Co 1 bien dau vao de xac dinh xem la hien thi so nao
{
switch(x)
{
case 0: { P0=0x40 ; break;} // So 0
case 1: { P0=0x79 ; break;}// So 1
case 2: { P0=0x24 ; break;}// So 2
case 3: { P0=0x30; break;}// So 3
case 4: { P0=0x19; break;}// so 4
case 5: { P0=0x12; break; }// so 5
case 6: { P0=0x2 ; break;} // So 6
case 7: { P0=0x78 ; break;}// So 7
case 8: { P0=0x0 ; break;}// So 8
case 9: { P0=0x10; break;}// So 9
}
}
void inhangtram()
{
LED_0=1;
LED_1=LED_2=0;
Hienthiled(hangtram);
}
void inhangchuc()
{
LED_1=1;
LED_0=LED_2=0;
Hienthiled(hangchuc);
}
void inhangdonvi()
{
LED_2=1;
LED_1=LED_0=0;
Hienthiled(hangdonvi);
}
void laymauADC1()
{
CS_1=0;
WR=1;
while (INTR_1==1);
CS_1=0;
RD=0;
}
void laymauADC2()
{
CS_2=0;
WR=1;
while (INTR_1==1);
CS_2=0;
RD=0;
}
void phiman()
{
if(P2_6==0)//phim1
{
INTR_1=1;
INTR_2=0;
laymauADC1();
}
if(P2_7==0)//phim2
{
INTR_1=0;
INTR_2=1;
laymauADC2();
}
}
void main(void)
{
{
phiman();
chuso();
inhangtram();
delay(1000);
inhangchuc();
delay(1000);
inhangdonvi();
delay(1000);
}
}
file mô phỏng có bên dưới!!!
Comment