#include<reg52.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit sck=P1^0;
sbit misi=P1^1;
sbit miso=P1^2;
sbit ss=P1^3;
sbit lcden=P2^0;
sbit lcdrw=P2^1;
sbit lcdrs=P2^2;
uchar code table[]={'0','1','2','3','4','5','6','7','8','9',
'a','b','c','d','e','f','g','h','i','j',
'k','l','m','n','o','p','q','r','s','t',
'u','v','w','x','y','z','A','B','C','D',
'E','F','G','H','I','J','K','L','M','N',
'O','P','Q','R','S','T','U','V','W','X',
'Y','Z',',','.',':',';','"','?','!','+',
'-','*','/'};
void lcd_com(uchar com);
void delay(uint t)
{
uint i;
while(t--)
for(i=500;i>0;i--);
}
uchar receive()
{
uchar i,date=0,temp;
bit bt;
ss=0;
for(i=0;i<8;i++)
{
sck=1;
_nop_();
_nop_();
_nop_();
bt=misi;
if(bt)
temp=0x01;
else
temp=0x00;
date<<=1;
date=(date|temp);
sck=0;
_nop_();
_nop_();
_nop_();
}
for(i=0;i<74;i++)
if(date==table[i]) return date;
}
void lcd_com(uchar com)
{
lcdrs=0;
lcdrw=0;
lcden=0;
delay(5);
P0=com;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void lcd_data(uchar dat)
{
lcdrs=1;
lcdrw=0;
lcden=0;
delay(5);
P0=dat;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void init()
{
lcden=0;
lcdrs=0;
lcd_com(0x38);
lcd_com(0x0f);
lcd_com(0x06);
lcd_com(0x01);
}
/*void string(uchar x,uchar y, uchar *str)
{
uchar address;
if(y==0)
address=0x00+x;
else
address=0x40+x;
lcd_com(address|0x80);
while(*str!=' ')
{
lcd_data(*str);
str++;
}
}*/
void main()
{
uchar message,i;
init();
P3=0xff;
for(i=0;i<16;i++)
{
message=receive();
lcd_data(message);
delay(10);
}
while(1);
}#include<reg52.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit sck=P1^0;
sbit misi=P1^1;
sbit miso=P1^2;
sbit ss=P1^3;
sbit lcden=P2^0;
sbit lcdrw=P2^1;
sbit lcdrs=P2^2;
uchar code table[]={'0','1','2','3','4','5','6','7','8','9',
'a','b','c','d','e','f','g','h','i','j',
'k','l','m','n','o','p','q','r','s','t',
'u','v','w','x','y','z','A','B','C','D',
'E','F','G','H','I','J','K','L','M','N',
'O','P','Q','R','S','T','U','V','W','X',
'Y','Z',',','.',':',';','"','?','!','+',
'-','*','/'};
void lcd_com(uchar com);
void delay(uint t)
{
uint i;
while(t--)
for(i=500;i>0;i--);
}
uchar receive()
{
uchar i,date=0,temp;
bit bt;
ss=0;
for(i=0;i<8;i++)
{
sck=1;
_nop_();
_nop_();
_nop_();
bt=misi;
if(bt)
temp=0x01;
else
temp=0x00;
date<<=1;
date=(date|temp);
sck=0;
_nop_();
_nop_();
_nop_();
}
for(i=0;i<74;i++)
if(date==table[i]) return date;
}
void lcd_com(uchar com)
{
lcdrs=0;
lcdrw=0;
lcden=0;
delay(5);
P0=com;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void lcd_data(uchar dat)
{
lcdrs=1;
lcdrw=0;
lcden=0;
delay(5);
P0=dat;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void init()
{
lcden=0;
lcdrs=0;
lcd_com(0x38);
lcd_com(0x0f);
lcd_com(0x06);
lcd_com(0x01);
}
/*void string(uchar x,uchar y, uchar *str)
{
uchar address;
if(y==0)
address=0x00+x;
else
address=0x40+x;
lcd_com(address|0x80);
while(*str!=' ')
{
lcd_data(*str);
str++;
}
}*/
void main()
{
uchar message,i;
init();
P3=0xff;
for(i=0;i<16;i++)
{
message=receive();
lcd_data(message);
delay(10);
}
while(1);
}
我想要从机只有接收到数据才返回给1602
一周热门 更多>