
(1)基于ATC52的同步串口通信
1单片机1程序
(程序在Kile C51上运行通过。)
/********************************************************************
* 文件名 : 液晶1602显示.c
* 描述 : 该程序实现了对液晶1602的控制。
* 创建人 : 东流,2009年4月10日
* 版本号 : 2.0
***********************************************************************/
#include #define uchar unsigned char #define uint unsigned int //这三个引脚参考资料 sbit E=P3^5; //1602使能引脚 sbit RW=P3^6; //1602读写引脚 sbit RS=P3^7; //1602数据/命令选择引脚 sbit aaa=P1^0; sbit bbb=P1^1; sbit aa=P3^0; sbit bb=P3^1; /******************************************************************** * 名称 : delay() * 功能 : 延时,延时时间大概为140US。 * 输入 : 无 * 输出 : 无 ***********************************************************************/ void delay() { int i,j; for(i=0; i<=100; i++) for(j=0; j<=20; j++) ; } /******************************************************************** * 名称 : enable(uchar del) * 功能 : 1602命令函数 * 输入 : 输入的命令值 * 输出 : 无 ***********************************************************************/ void enable(uchar del) { P2 = del; RS = 0; RW = 0; E = 0; delay(); E = 1; delay(); } /******************************************************************** * 名称 : write(uchar del) * 功能 : 1602写数据函数 * 输入 : 需要写入1602的数据 * 输出 : 无 ***********************************************************************/ void write(uchar del) { P2 = del; RS = 1; RW = 0; E = 0; delay(); E = 1; delay(); } /******************************************************************** * 名称 : L1602_init() * 功能 : 1602初始化,请参考1602的资料 * 输入 : 无 * 输出 : 无 ***********************************************************************/ void L1602_init(void) { enable(0x01); enable(0x38); enable(0x0c); enable(0x06); enable(0xd0); } /******************************************************************** * 名称 : L1602_char(uchar hang,uchar lie,char sign) * 功能 : 改变液晶中某位的值,如果要让第一行,第五个字符显示"b" ,调用该函数如下 L1602_char(1,5,'b') * 输入 : 行,列,需要输入1602的数据 * 输出 : 无 ***********************************************************************/ void L1602_char(uchar hang,uchar lie,char sign) { uchar a; if(hang == 1) a = 0x80; if(hang == 2) a = 0xc0; a = a + lie - 1; enable(a); write(sign); } /******************************************************************** * 名称 : L1602_string(uchar hang,uchar lie,uchar *p) * 功能 : 改变液晶中某位的值,如果要让第一行,第五个字符开始显示"ab cd ef" ,调用该函数如下 L1602_string(1,5,"ab cd ef;") * 输入 : 行,列,需要输入1602的数据 * 输出 : 无 ***********************************************************************/ void L1602_string(uchar hang,uchar lie,uchar *p) { uchar a; if(hang == 1) a = 0x80; if(hang == 2) a = 0xc0; a = a + lie - 1; enable(a); while(1) { if(*p !='\\0') write(*p); else break; p++; } } /******************************************************************** * 名称 : Main() * 功能 : 主函数 * 输入 : 无 * 输出 : 无 ***********************************************************************/ void Main() { uchar k[]="sbuf data:"; uchar i = 122,j=1,ti=14; aaa=1;bbb=1; aa=1;bb=1; SM0=0;SM1=0; SM2=0;REN=1; L1602_init(); L1602_char(1,5,SBUF); L1602_string(1,1,k); while(ti>=0) { while(1) {if(aaa==0) {bbb=0;break;} } aaa=1;bbb=1; i--; i--; i--; i--; i--; i--; RI=0; while(1) { if(RI!=0)break; } L1602_char(2,j,SBUF); j++;ti--; } REN=0;RI=1; while(5)i=0; } 2单片机2程序 #include sbit a=P2^0; sbit b=P2^1; sbit C=P3^1; void main() {int i=0 ,j=0; char str[20]=" www.baidu.com"; a=1;b=1; SM0=0;SM1=0; SM2=0;//RI=0; while(j<=14) { for(i=0;i<=100;i++); a=0;//SBUF=0; while(1) { if(b==0)break;} b=1;a=1; SBUF=str[j]; TI=0; j++; } while(1); } (2)基于MSP430的科学计算器 单片机程序: (程序在IAR430上运行通过。) #include #include #include #include #include unsigned char dis1[]="WORK START"; //状态显示 unsigned char dis2[]="ALCOHOL TEST"; char dis,j,a,c,cls[]=" "; char ak,ch=1,aa[20],bb[20]; char i=0,n=0,m=0,flag=1,pf=1,dnf=0,deng=0,du=0; double sum=0,sum1=0; //int c=7; void delay(unsigned char ms) //延时1 { unsigned char i,j; while(ms--) { for(i=0;i<65;i++) for(j=0;j<50;j++) { } } } void delay2(unsigned int time ) //延时2 { unsigned int n; n=0; while (n
