51单片机串口通信仿真实现16 16点阵显示程序
时间:11-23
来源:互联网
点击:
首先要了解串口通信的基本工作原理,连接图如下:
虚拟终端连接:
单片机+虚拟终端(作为串口输入设备)+串口
连接图如下:
设置如下:
单片机虚拟终端选项作用如下:
如果输入的是ASCII码,那么就不要勾选 Hex Display Mode
如果输入的是16进制,那么就不要勾选 Hex Display Mode
Clear Screen 是清屏
Echo Typed Characters 是你在虚拟终端窗口输入字符时,输入的字符显示在虚拟终端窗口上。
具体C程序如下(如有疑问联系本人,新浪微博地址:
#include
#define uint unsigned int
#define uchar unsigned char
unsigned char a,flag;
char code YD[]={
0x01,0x00,0x01,0x00,0x7F,0xFC,0x03,0x80,
0x05,0x40,0x09,0x30,0x31,0x0E,0xDF,0xE4,
0x00,0x80,0x01,0x00,0x7F,0xFE,0x01,0x00,
0x01,0x00,0x01,0x00,0x05,0x00,0x02,0x00,
0x20,0x40,0x30,0x40,0x24,0x4C,0x42,0x70,
0xFF,0x44,0x42,0x46,0x00,0x7C,0x7E,0x00,
0x42,0x40,0x7E,0x4C,0x42,0x70,0x7E,0x40,
0x42,0x44,0x42,0x46,0x4A,0x3C,0x44,0x00,
0x00,0x00,0x0F,0xF0,0x08,0x10,0x0F,0xF0,
0x08,0x10,0x0F,0xF0,0x00,0x00,0xFF,0xFE,
0x01,0x00,0x09,0x00,0x09,0xF8,0x09,0x00,
0x15,0x00,0x23,0x00,0x40,0xFE,0x00,0x00,
0x01,0x00,0x01,0x00,0x02,0x80,0x02,0x40,
0x04,0x20,0x09,0x18,0x11,0x0E,0x61,0x04,
0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,
0x01,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,
0x01,0x00,0xFF,0xFE,0x01,0x00,0x02,0x80,
0x02,0x80,0x02,0x40,0x04,0x40,0x04,0x20,
0x08,0x10,0x10,0x18,0x20,0x0E,0x40,0x04,/
0x08,0x20,0x08,0x20,0x08,0x20,0x4B,0xFE,
0x4A,0x22,0x4A,0x22,0x4A,0x22,0x4A,0x22,
0x4A,0x22,0x4A,0x22,0x4A,0x22,0x12,0x2E,
0x12,0x24,0x20,0x20,0x40,0x20,0x80,0x20,
0x00,0x00,0x7F,0xFC,0x00,0x10,0x1F,0x90,
0x10,0x90,0x1F,0x90,0x10,0x90,0x00,0x04,
0xFF,0xFE,0x00,0x10,0x1F,0x90,0x10,0x90,
0x1F,0x90,0x10,0x90,0x00,0x50,0x00,0x20
};
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void main()
{
int i;
TMOD=0x20;//设置定时器1为工作方式2
TH1=0xfd;
TH2=0xfd;//设置波特率为9600
TR1=1;//启动定时器1
SM0=0;
SM1=1;//选择串口工作方式1
REN=1;//允许接收数据
EA=1;//打开总中断
ES=1;//打开串口中断
while(1)
{
if(flag==1)
{
flag=0;
while(1)
{
if(a==0x31)//键盘码十六进制
{
for(i=0;i<16;i++)
{
P1=i;
P0=~YD[2*i];
P2=~YD[2*i+1];
delay(2);
}
}
if(a==0x32)
{
for(i=1;i<17;i++)
{
P1=i;
P0=~YD[32+2*i];
P2=~YD[32+2*i+1];
delay(2);
}
}
if(a==0x33)
{
for(i=1;i<17;i++)
{
P1=i;
P0=~YD[64+2*i];
P2=~YD[64+2*i+1];
delay(2);
}
}
if(a==0x34)
{
for(i=1;i<17;i++)
{
P1=i;
P0=~YD[96+2*i];
P2=~YD[96+2*i+1];
delay(2);
}
}
if(a==0x35)
{
for(i=1;i<17;i++)
{
P1=i;
P0=~YD[128+2*i];
P2=~YD[128+2*i+1];
delay(2);
}
}
if(a==0x36)
{
for(i=1;i<17;i++)
{
P1=i;
P0=~YD[160+2*i];
P2=~YD[160+2*i+1];
delay(2);
}
}
if(a==0x37)
{
for(i=1;i<17;i++)
{
P1=i;
P0=~YD[192+2*i];
P2=~YD[192+2*i+1];
delay(2);
}
}
}//第二个while结尾
}//if结尾
}//第一个while结尾
}//主函数结尾
void ser() interrupt 4
{
RI=0;//接受中断标志位,清0为取消中断申请
a=SBUF;//接收数据
flag=1;//中断标志位
}
虚拟终端连接:
单片机+虚拟终端(作为串口输入设备)+串口
连接图如下:
设置如下:
单片机虚拟终端选项作用如下:
如果输入的是ASCII码,那么就不要勾选 Hex Display Mode
如果输入的是16进制,那么就不要勾选 Hex Display Mode
Clear Screen 是清屏
Echo Typed Characters 是你在虚拟终端窗口输入字符时,输入的字符显示在虚拟终端窗口上。
具体C程序如下(如有疑问联系本人,新浪微博地址:
http://t.sina.com.cn/1858560312):
#include#include
#define uint unsigned int
#define uchar unsigned char
unsigned char a,flag;
char code YD[]={
0x01,0x00,0x01,0x00,0x7F,0xFC,0x03,0x80,
0x05,0x40,0x09,0x30,0x31,0x0E,0xDF,0xE4,
0x00,0x80,0x01,0x00,0x7F,0xFE,0x01,0x00,
0x01,0x00,0x01,0x00,0x05,0x00,0x02,0x00,
0x20,0x40,0x30,0x40,0x24,0x4C,0x42,0x70,
0xFF,0x44,0x42,0x46,0x00,0x7C,0x7E,0x00,
0x42,0x40,0x7E,0x4C,0x42,0x70,0x7E,0x40,
0x42,0x44,0x42,0x46,0x4A,0x3C,0x44,0x00,
0x00,0x00,0x0F,0xF0,0x08,0x10,0x0F,0xF0,
0x08,0x10,0x0F,0xF0,0x00,0x00,0xFF,0xFE,
0x01,0x00,0x09,0x00,0x09,0xF8,0x09,0x00,
0x15,0x00,0x23,0x00,0x40,0xFE,0x00,0x00,
0x01,0x00,0x01,0x00,0x02,0x80,0x02,0x40,
0x04,0x20,0x09,0x18,0x11,0x0E,0x61,0x04,
0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,
0x01,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,
0x01,0x00,0xFF,0xFE,0x01,0x00,0x02,0x80,
0x02,0x80,0x02,0x40,0x04,0x40,0x04,0x20,
0x08,0x10,0x10,0x18,0x20,0x0E,0x40,0x04,/
0x08,0x20,0x08,0x20,0x08,0x20,0x4B,0xFE,
0x4A,0x22,0x4A,0x22,0x4A,0x22,0x4A,0x22,
0x4A,0x22,0x4A,0x22,0x4A,0x22,0x12,0x2E,
0x12,0x24,0x20,0x20,0x40,0x20,0x80,0x20,
0x00,0x00,0x7F,0xFC,0x00,0x10,0x1F,0x90,
0x10,0x90,0x1F,0x90,0x10,0x90,0x00,0x04,
0xFF,0xFE,0x00,0x10,0x1F,0x90,0x10,0x90,
0x1F,0x90,0x10,0x90,0x00,0x50,0x00,0x20
};
void delay(uint z)
{
}
void main()
{
}//主函数结尾
void ser() interrupt 4
{
}
51单片机串口通信点阵显 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)