Доделать программу "Шахматные часы"
Создать программу "Шахматные часы" в среде Keil uVision 5 для микропроцессора ADuC842 на языке C51.
незаконченная программа
#include
sbit RS=0xb5; //podkluchaem JKI
sbit RW=0xb6;
sbit E=0xb7;
sfr DATA=0xa0;
sbit P0_4=0x84; //podkluchaem klaviaturu
sbit P0_5=0x85;
sbit P0_6=0x86;
sbit P1_0=0x90;
sbit P1_1=0x91;
sbit P1_2=0x92;
sbit P1_3=0x93;
unsigned int Counter, Hours, Min, Sec;
unsigned char KeyNum(void) //programma obrabotki klaviatyri
{
P1=0;
P0_4=0;
P0_5=1;
P0_6=1;
if(P1_0==0)return(1);
if(P1_1==0)return(4);
if(P1_2==0)return(7);
if(P1_3==0)return(10);
P0_4=1;
P0_5=0;
P0_6=1;
if(P1_0==0)return(2);
if(P1_1==0)return(5);
if(P1_2==0)return(8);
if(P1_3==0)return(11);
P0_4=1;
P0_5=1;
P0_6=0;
if(P1_0==0)return(3);
if(P1_1==0)return(6);
if(P1_2==0)return(9);
if(P1_3==0)return(12);
return(0);
}
void Delay(unsigned int T) //nastroika T0 na 100 mks
{
unsigned int I;
TMOD=(TMOD & 0xfc);
TMOD=(TMOD | 0x01);
TF0=0;
TR0=0;
for(I=0;I
{TH0=0xff;
TL0=0x2e;
TR0=1;
while(TF0==0);
TF0=0;
}
}
void LCD_SEND(bit c0d1, unsigned char byte_to_send) //peresilka danniih na display
{
RS=c0d1;
RW=0;
E=1;
DATA=byte_to_send;
Delay(1);
E=0;
Delay(1);
}
void LCD_INIT(void) //inicializaciya JKI
{
Delay(200);
LCD_SEND(0,0x30);
Delay(40);
LCD_SEND(0,0x30);
LCD_SEND(0,0x30);
LCD_SEND(0,0x38);
LCD_SEND(0,0x0f);
LCD_SEND(0,0x06);
LCD_SEND(0,0x01);
Delay(50);
}
void Time(void)
{
unsigned char T[5];
unsigned char I;
if(Sec>59) Sec--;
else
{Sec=0;
if(Min>59)Min--;
else
{Min=0;
if(Hours>1)Hours--;
else Hours=0;
}
}
T[0]=Hours/10+0x30;
T[1]=Hours%10+0x30;
T[2]=0x3a;
T[3]=Min/10+0x30;
T[4]=Min%10+0x30;
if (Hours==0);
{
T[0]=Min/10+0x30;
T[1]=Min%10+0x30;
T[2]=0x3a;
T[3]=Sec/10+0x30;
T[4]=Sec%10+0x30;
}
LCD_SEND(0,0x80);
for(I=0;I
LCD_SEND(1,T);
}
void IntT2(void) interrupt 5 using 3
{
TF2=0;
Counter--;
if(Counter==0)
{Counter=40;
Time();
}
}
void main(void)
{