甲机程序+乙机程序甲机程序+乙机程序
/*甲机程序*/
#include #define uchar unsigned char
sbit K1 = P1^0;
uchar LED_NO = 0; uchar code DSY_code[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void DELAY_ms(uchar m) {
uchar i;
while(m--)
{
for(i=0;i=0 && SBUF #define uchar unsigned...
甲机程序+乙机程序
/*甲机程序*/
#include #define uchar unsigned char
sbit K1 = P1^0;
uchar LED_NO = 0; uchar code DSY_code[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void DELAY_ms(uchar m) {
uchar i;
while(m--)
{
for(i=0;i<120;i++);
}
}
void Put_2_sport(uchar c) {
SBUF = c;
while(TI==0);
TI = 0;
}
void main()
{
P0 = 0; //关闭数码管
SCON = 0x50; //串口模式1,允许接收
TMOD = 0x20; //T1定时器,模式2
PCON = 0x00; //波特率不倍增
TH1 = 0xFD; //波特率9600
TL1 = 0xFD;
TI = 0;
RI = 0;
IE = 0x90; //允许串口中断
TR1 = 1; //计时开始
while(1)
{
DELAY_ms(50);
if(K1==0)
{
while(K1==0);
LED_NO = (LED_NO + 1)%4;
switch(LED_NO)
{
case 0: Put_2_sport(0); break;
case 1: Put_2_sport(1); break;
case 2: Put_2_sport(2); break;
case 3: Put_2_sport(3);
}
}
}
}
void S_INT() interrupt 4
{
if(RI) //接收完一个字节
{
RI = 0;
if(SBUF>=0 && SBUF<=9) P0 = DSY_code[SBUF];
else P0 = 0x00;
}
}
/*乙机程序*/
#include #define uchar unsigned char
sbit LED1 = P0^0; sbit LED2 = P0^3; sbit K2 = P1^0; uchar NO = 0x00;
void DELAY_ms(uchar m)
{
uchar i;
while(m--)
{
for(i=0;i<120;i++);
}
}
void main()
{
LED1 = LED2 = 1;
SCON = 0x50;
TMOD = 0x20;
TH1 = 0xFD;
TL1 = 0xFD;
PCON = 0x00;
TI = RI =0;
IE = 0x90;
TR1 = 1;
while(1)
{
DELAY_ms(50);
if(K2==0)
{
while(K2==0);
NO = (NO+1)%11; //0-10数字
SBUF = NO;
while(TI==0);
TI = 0;
}
}
}
void S_INT() interrupt 4
{
if(RI)
{
RI = 0;
switch(SBUF)
{
case 0: LED1 = 1; LED2 = 1; break;
case 1: LED1 = 0; LED2 = 1; break;
case 2: LED1 = 1; LED2 = 0; break;
case 3: LED1 = 0; LED2 = 0;
}
}
}
本文档为【甲机程序+乙机程序】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。