#include <reg52.h>
#define uchar unsigned char
#include <stdio.h>
unsigned char* c
sbit l0=P3^2
sbit l1=P3^3
sbit k0=P3^4
sbit k1=P3^5
sbit k2=P3^7
sbit k3=P1^7
uchar s1,s2
bit y0,y1,y2,y3,y4,y5
bit t1,t2,ld
uchar table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d}
void delay(uchar z) // 延时
{
uchar i,j
for(i=0i<120i++)
for(j=0j<zj++)
}
void SendOneChar(char c) //发送字节到PC
{
TI=0
SBUF = c
while(!TI)
TI=0
}
void SendString(char *st) //发送字符串到PC
{
while(*st)
{
SendOneChar(*st++)
}
}
void main()
{
SCON = 0x50 //SCON: mode 1, 8-bit UART, enable rcvr
TMOD = 0x20 //TMOD: timer 1, mode 2, 8-bit reload
PCON = 0x80 // 数据位8、停止位1。效验位无 (11.0592M)
TH1 = 0xF4 //TH1: reload value for 2400@11.0592MHz
TR1 = 1 //启动定时器1
ES = 1 //允许串口中断位
EA = 1 氏昌 //允许总中断位
c=0
t2=1
s1=0
s2=0
l0 = 0 l1 = 0
while(1)
{
if(k0==0 &&y0==0)
{
y0=1
c = "as"
SendString(c) //发送字符串
}
if(k0==1 ) { y0=0}
if(k1==0 &&y1==0)
{
y1=1
c = "bs"
SendString(c) //发送字符串
}
if(k1==1 ) { y1=0}
if(k2==0 &&y2==0)
{
y2=1
c = "ds"
SendString(c) 首核搜 //发送字符串
}
if(k2==1 ) { y2=0}
if(k3==0 &&y3==0)
{
y3=1
s1 = 0
s2 = 0 //清零
}
if(k3==1 ) { y3=0}
l1 = 0
P1 =~table[s1]
l0 = 1
delay(5)
l0 = 0
P1 =~table[s2]
l1 = 1
delay(5)
// for(i = 0i <4000i++) //延迟一小段时间者历
}
}
void chuankou(void) interrupt 4
{
if(RI==1)
{
RI = 0
if(t1==1)
{
if(SBUF=='z') { s1++ld=~ld}
t1=0t2=1
if(s1==10) { s1=0s2++}
if(s2==10) { s2=0}
// led1=ld
}
if(SBUF=='a' &&t2==1) { t1=1t2=0}
}
}
///////////////////////
#include <reg51.h>// 接收 试试
#define uchar unsigned char
unsigned char* c
sbit l0=P3^2 // 接收 az ,
sbit l1=P3^3 // 接收 aa ,
sbit k0=P3^5
sbit k1=P3^7
bit y0,y1,t1,t2
uchar s1,s2
uchar table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d}
void delay(uchar z) // 延时
{
uchar i,j
for(i=0i<120i++)
for(j=0j<zj++)
}
void SendOneChar(char c) //发送字节到PC
{
TI=0
SBUF = c
while(!TI)
TI=0
}
void SendString(char *st) //发送字符串到PC
{
while(*st)
{
SendOneChar(*st++)
}
}
void main (void)
{
SCON = 0x50 // REN=1允许串行接受状态,串口工作模式1
TMOD = 0x21 // 定时器工作方式2
PCON = 0x80 // 数据位8、停止位1。效验位无 (11.0592M)
TH1 = 0xF4 // TH1 = 0xFD波特率 2400
TH0=(65536-54253)/256 // 50 mS
TL0=(65536-54253)%256
TR1 = 1
ES = 1 // 开串口中断
EA = 1 // 开总中断
// ET0=1
// TR0=1
t2=1
s1=0 s2=0
while(1)
{
if(k0==0 &&y0==0)
{
y0=1
c = "az"
SendString(c) //发送字符串
}
if(k0==1 ) { y0=0}
if(k1==0 &&y1==0)
{
y1=1
s1 = 0
s2 = 0 //清零
}
if(k1==1 ) { y1=0}
l1 = 0
P1 =~table[s1]
l0 = 1
delay(5)
l0 = 0
P1 =~table[s2]
l1 = 1
delay(5)
}
}
void chuankou(void) interrupt 4
{
if(RI==1)
{
RI = 0
if(t1==1)
{
if(SBUF=='s') { s1++}
t2=1t1=0
if(s1==10) { s1=0s2++}
if(s2==10) { s2=0}
}
if(SBUF=='a' &&t2==1) { t1=1t2=0}
}
}
void T0_time()interrupt 1
{
TH0=(65536-54253)/256 // 50 mS
TL0=(65536-54253)%256
s1++
if(s1==10) // 这里修改时间
{
s1=0s2++
}
if(s2==10) { s2=0}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)