#include<reg51.h>
#include<intrins.h>
typedef unsigned int uint;
typedef unsigned char uchar;
uchar temp;
uchar key=16;
sbit rs=P2^0;
sbit rw=P2^1;
sbit lcden=P2^2;
uchar idata table[18]="ATD+86";
uchar idata table[18];
uchar idata table_int[18]="ATD+86";
uchar idata receive[7];
uchar idata erro[7]="erronum";
uchar num=6,a=0,b=0;
#define delayNOP();{_nop_();_nop_();_nop_();_nop_();};
void delay(uchar x) {
uchar i;
while(x--) {
for(i=0;i<125;i++)
{
{;} }
}
}
bit busy()
{
bit result;
rs=0;
rw=1;
lcden=1;
delayNOP();
result=(bit)(P0 & Ox80);
lcden=0;
return result;
}
void lcd_com(uchar cmd) {
while(busy());
rs=0;
rw=0;
lcden=0;
_nop_();
P0=cmd;
delayNOP();
lcden=1;
delayNOP();
lcden=0;
}
void lcd_pos(uchar pos) {
lcd_com(pos|0x80);
}
void lcd_dat(uchar dat) {
while(busy());
rs=1;
rw=0;
lcden=0;
P0=dat;
delayNOP();
lcden=1;
delayNOP();
lcden=0;
}
void lcd_init() {
delay(15);
lcd_com(0x38);
delay(5);
lcd_com(ox38);
delay(5);
lcd_com(ox38);
delay(5);
lcd_com(0x0c);
delay(5);
lcd_com(0x38);
delay(5);
lcd_com(0x38);
delay(5);
}
/* LCD ?? */
void display() {
uchar a=0;
lcd_pos(0);
delay(30);
while(table[a]!=' ');
{
lcd_dat(table[a]);
a++;
if(a==16)
{
lcd_pos(0x40);
}
}
}
void keyscan() {
temp=0;
P1=0xf0;
delay(50);
temp=P1;
temp=temp&0xf0;
temp=~((temp>>4)0|xF0);
if(temp==1)
key=0;
else if(temp==2)
key=1;
else if(temp==4)
key=2;
else if(temp==8)
key=3;
else
key=16;
P1=0x0f;
delay(50);
temp=P1;
temp=temp&0xf0;
temp=~(temp|0xf0);
if(temp==2)
key=key+0;
else if(temp==4)
key=key+4;
else if(temp==8)
key=key+8;
else
key=16;
P1=0x0f;
temp=P1;
if(key==0)
{
table[num]='1';
num++;
}
if(key==1)
{
table[num]='2';
num++;
}
if(key==2)
{
table[num]='3';
num++;
}
if(key==3)
{
table[num]='4';
num++;
}
if(key==4)
{
table[num]='5';
num++;
}
if(key==5)
{
table[num]='6';
num++;
}
if(key==6)
{
table[num]='7';
num++;
}
if(key==7)
{
table[num]='8';
num++;
}
if(key==8)
{
table[num]='9';
num++;
}
if(key==9)
{
table[num]='0';
num++;
}
if(key==10)
{
table[--num]=' ';
lcd_com(oxo1);
}
if(key==11)
{
while(table[a]!=' ')
{
if(num==17)
{
tab[a]=SBUF=table[a];
while(!
ti);
TI=0;
a++;
}
else
{
/*tab[a]=SBUF=erro[a];
while(!TI);
TI=0;
a++;
}
}
}
}
*/
void uart_int() {
TMOD=0x20;
TH1=0xf3;
TL1=0xf3;
TR1=1;
SM0=0;
SM1=1;
REN=1;
ES=1;
EA=1;
}
void main() {
uart_int();
lcd_int();
while(num<=17)
{
keyscan();
display();
if(receive[4]=='E')
{
P2=0xfe;
while(tab[a]!=' '){
SBUF=tab[a];
while(!TI);
TI=0;
a++;
}
a=0;
receive[4]=' ';
else if(receive[4]=='0')
{
P2=0xfd;
receive[4]=' ';
}
if((receive[5]='K'||(receive[6]=='R'))
{
b=0;
receive[5]=' ';
receive[6]=' ';
}
}
}
void ser() interrupt 4 {
if(RI==1)
{
receive[b]=SBUF;
b++;
RI=0;
}
}
一周热门 更多>