12864显示程序,51单片机,C语言
51单片机和12864液晶显示实例——C语言
#include <reg51.h>#define unchar unsigned char #define unint unsigned intsbit RS=P2^7;sbit RW=P2^6;sbit E=P2^5;void delay(unsigned int t){unsigned int i,j;for(i=0;i<t;i++)for(j=0;j<10;j++);}void busy(){RS=0;RW=1;E=1;P0=0xff;while((P0&0X80)==0x80); }void write_com(unchar com) {busy();RS=0;RW=0;E=1;P0=com;delay(5);E=0;delay(5);}void write_date(unchar date) {busy();RS=1;RW=0;E=1;P0=date;// delay(5);E=0;// delay(5);}void init(){delay(2000);write_com(0x30); //选择基本指令,选择8位数据流delay(5);write_com(0x0c); //开显示(无游标,不反白)delay(10);write_com(0x01); //清除显示,并且设定地址指针为00H delay(500);write_com(0x06);// 设定游标移动方向}void sendaddr(unchar n,unchar m){switch(n){case 1:write_com(0x80+m);break;case 2:write_com(0x90+m);break;case 3:write_com(0x88+m);break;case 4:write_com(0x98+m);break;}}void display(unchar n,unchar m,unchar *s){sendaddr(n,m);while(*s>0){write_date(*s);s++;delay(100);}}void main(){unchar *s;init();s="甲:“我来了”";display(1,0,s);s="乙:“热烈欢迎。
12864液晶显示程序51驱动
#include <reg52.h>#include <intrins.h>sbit LCD_RS =P0^0; //L:COMMAND; H:DATA sbit LCD_RW =P0^1; //L:WRITE; H:READ sbit LCD_E =P0^2; //INPUT ENABLEsbit LCD_CS1 =P0^3; //L有效sbit LCD_RES =P0^4; //L有效#define data_bus P2#define control_bus P0#define uchar unsigned char#define uint unsigned int//=====延时N微秒==============void delay_nus(uint n){while(n--);return;}//=====延时N毫秒==============void delay_nms(uint n){int i;for(i=0;i<n;i++)delay_nus(123);}//=====忙检测=================void check_busy(void){uchar read_data=0xff;data_bus=0xff;LCD_RS=0;LCD_RW=1; //读命令LCD_CS1=0; //片使能while((read_data&0x80)==0x80){LCD_E=1;_nop_();_nop_();read_data=data_bus;LCD_E=0;}LCD_E=0;LCD_CS1=1; //片禁能}//=====写命令到寄存器========= void send_cmd(uchar cmd) small{check_busy();LCD_RS=0; //写的是命令LCD_RW=0; //写命令LCD_CS1=0; //片使能data_bus=cmd;LCD_E=1; //使能_nop_();_nop_();LCD_E=0;_nop_();_nop_();LCD_CS1=1; //片禁能}//=====写数据到DDRAM========= void send_dat(uchar dat) small{check_busy();LCD_RS=1; //写的是数据LCD_RW=0; //写数据LCD_CS1=0; //片使能data_bus=dat;LCD_E=1;_nop_();_nop_();LCD_E=0;_nop_();_nop_();LCD_CS1=1; //片禁能}//=======初始化============== void lcd_initial(void) small{LCD_RES=0;delay_nms(50);LCD_RES=1;LCD_E=0;delay_nms(50);send_cmd(0xA0);send_cmd(0xC8);send_cmd(0xA2);send_cmd(0x2C);send_cmd(0x2E);send_cmd(0x2F);send_cmd(0x25);send_cmd(0x81);send_cmd(0x14);send_cmd(0xAF);send_cmd(0xE0);send_cmd(0x40);}//=======写列地址==============void Set_Colume_Address(unsigned char dat){unsigned char tmp;tmp=dat>>4;send_cmd(0x10|tmp); //送列地址高三位tmp=0x0f&dat;send_cmd(tmp); //送列地址低四位}code unsigned char number[][16] = {/*-- 文字: 0 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,/*-- 文字: 1 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,/*-- 文字: 2 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,/*-- 文字: 3 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,/*-- 文字: 4 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,/*-- 文字: 6 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,/*-- 文字: 7 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,/*-- 文字: 8 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,/*-- 文字: 9 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,/*-- 文字: : --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00, /*-- 文字: - --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01}; code unsigned char Hz[][32] = {/*-- 文字: 中--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x00,0xFC,0x08,0x08,0x08,0x08,0xFF,0x08,0x08,0x08,0x08,0xFC,0x08,0x00,0x00, 0x00,0x00,0x07,0x02,0x02,0x02,0x02,0xFF,0x02,0x02,0x02,0x02,0x07,0x00,0x00,0x00,/*-- 文字: 鼎--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x00,0xF8,0x00,0x00,0x7E,0x52,0x66,0x4A,0x52,0x7E,0x00,0x00,0xF8,0x00,0x00, 0x00,0x84,0x65,0x1D,0x05,0x05,0xFF,0x00,0x00,0xFF,0x05,0x05,0x05,0xFD,0x00,0x00,/*-- 文字: 技--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x08,0x08,0x88,0xFF,0x48,0x28,0x00,0xC8,0x48,0x48,0x7F,0x48,0xC8,0x48,0x08,0x00, 0x01,0x41,0x80,0x7F,0x00,0x40,0x40,0x20,0x13,0x0C,0x0C,0x12,0x21,0x60,0x20,0x00,/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x10,0x10,0x10,0x10,0x10,0x90,0x50,0xFF,0x50,0x90,0x12,0x14,0x10,0x10,0x10,0x00, 0x10,0x10,0x08,0x04,0x02,0x01,0x00,0x7F,0x00,0x00,0x01,0x06,0x0C,0x18,0x08,0x00 };/****显示汉字的程序****/void DisplayHz(unsigned int Page,unsigned int Col,unsigned char Hz[],unsigned int zilie) {unsigned int PageCnt,ColCnt;for(PageCnt = Page;PageCnt < Page+2;PageCnt ++){send_cmd(0xb0|PageCnt); //page addressSet_Colume_Address(Col);for(ColCnt = 0;ColCnt < zilie;ColCnt ++){send_dat(Hz[(PageCnt-Page)*zilie + ColCnt]);}}}//=====主程序===================void main (void){unsigned char month=0,nian=10,yue=1,tian=1,shi=0,fen=0,miao=0,i=0,j=0; unsigned char months[12]={31,28,31,30,31,30,31,31,30,31,30,31};lcd_initial();send_cmd(0xa6);for(i=0;i<8;i++) //清屏{send_cmd(0xb0|i);Set_Colume_Address(0);for(j=0;j<128;j++)send_dat(0);}while(1){if(++miao>59){miao=0;if(++fen>59){fen=0;if(++shi>23){shi=0;if(++tian>months[month]){tian=0;if(++yue>11){yue=1;nian++;}}}}}DisplayHz(0,0,number[nian/10],8);DisplayHz(0,16,number[nian%10],8);DisplayHz(0,32,number[11],8);DisplayHz(0,48,number[yue/10],8);DisplayHz(0,64,number[yue%10],8);DisplayHz(0,80,number[11],8);DisplayHz(0,96,number[tian/10],8);DisplayHz(0,112,number[tian%10],8);DisplayHz(3,0,number[shi/10],8);DisplayHz(3,16,number[shi%10],8);DisplayHz(3,32,number[10],8);DisplayHz(3,48,number[fen/10],8);DisplayHz(3,64,number[fen%10],8);DisplayHz(3,80,number[10],8);DisplayHz(3,96,number[miao/10],8);DisplayHz(3,112,number[miao%10],8);DisplayHz(6,14,Hz[0],16);DisplayHz(6,42,Hz[1],16);DisplayHz(6,70,Hz[2],16);DisplayHz(6,98,Hz[3],16);delay_nms(6000);}}。
单片机制作的12864液晶万年历_C语言程序
#include<reg52.H>#include<intrins.h>#include<math.h>////////////////////////////////////////DS18B20#define uchar unsigned char#define uint unsigned intsbit DQ = P1 ^ 0; // 定义DS18B20的单总线#define Lcd_Bus P0sbit LCD_RS=P2^7; //数据/命令选择sbit LCD_RW=P2^6; //读写控制sbit LCD_EN=P2^5; //片选信号#define LCD_DA TA P0 //8 bit数据线#define LOW 0#define HIGH 1//初始化指令#define CLEAR_SCREEN 0x01 //清屏指令:清屏且AC值为00H#define AC_INIT 0x02 //将AC设置为00H。
且游标移到原点位置#define CURSE_ADD 0x06 //设定游标移到方向及图像整体移动方向(默认游标右移,图像整体不动)#define FUN_MODE 0x30 //工作模式:8位基本指令集#define DISPLAY_ON 0x0c //显示开,显示游标,且游标位置反白#define DISPLAY_OFF 0x08 //显示关#define CURSE_DIR 0x14 //游标向右移动:AC=AC+1#define SET_CG_AC 0x40 //设置AC,范围为:00H~3FH#define SET_DD_AC 0x80#define FUN_MODEK 0x36 //扩展指令集,8位指令#define X1address 0x80 //上半屏X轴起始地址#define X2address 0x88 //下半屏X轴起始地址#define Y address 0x80 //Y轴起始地址#define Set_Column 0x40#define Set_Page 0xB8uchar code shu[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};uchar code xingqi[]="星期";uchar code hanzishu[]="一二三四五六日";unsigned char TempData = 0;double DS18B20Data;uint jiemian=0;//////////////////////////////////////////DS1302sbit DS1302_RST = P1^4;sbit DS1302_IO = P1^3;sbit DS1302_SCK = P1^2;unsigned char table[]={0X00,0X18,0X0c,0X15,0X06,0X01,0X0a};//0s 24min 12hour 14ri 5yue 5zhou 2010nianunsigned char data table1[7];//uchar code table2[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};uchar code shuzi[]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,};unsigned char aa,bb;uchar miaoge,miaoshi,fenge,fenshi,shige,shishi,rige,rishi,yuege,yueshi,zhou,niange,nianshi;uchar shezhinum=0;//unsigned char shi,ge;////////////////////////////////////////////////键盘扫描sbit key_mnue = P3^7;sbit key_jia = P2^0;sbit key_jian = P2^1;sbit key_enter= P2^2;uchar key_number=0;//int nian,yue,ri,shi,fen;/////////////////////////////////////////////////红外sbit HW_IRQ = P3 ^ 2; // 定义38KHz一体化红外接收头与CPU的连接unsigned char DT;static unsigned char data IRCode[3],IRCON,IRCON2;//////////////////////////////////////////////////蜂鸣器sbit BEEP =P1^1;/****************************************************************************** *************** 函数名称:DS18B20_Delay()* 功能:DS18B20软件延时专用* 入口参数:count 延时参数,值越大,延时越长* 出口参数:无******************************************************************************* **************/void DS18B20_Delay(uint count) //延时函数{while(count--);}/****************************************************************************** *************** 函数名称:DS18B20_Init()* 功能:DS18B20初始化* 入口参数:无* 出口参数:返回值为1则初始化成功* 返回值为0则初始化失败******************************************************************************* **************/uchar DS18B20_Init(void){uchar x = 0;DQ = 1; // DQ复位DS18B20_Delay(8); // 稍做延时DQ = 0; // 单片机将DQ拉低DS18B20_Delay(80); // 精确延时,大于480usDQ = 1; // 拉高总线DS18B20_Delay(14); // 稍做延时后x = DQ; // 若x=0则初始化成功,若x=1则初始化失败DS18B20_Delay(20);return (~x);}/****************************************************************************** *************** 函数名称:DS18B20_Read1Byte()* 功能:从DS18B20读一个字节* 入口参数:无* 出口参数:从DS18B20读出的一个字节******************************************************************************* **************/uchar DS18B20_Read1Byte(void){uchar i = 0;uchar dat = 0;for(i=8;i>0;i--){DQ = 0; // 给脉冲信号dat >>= 1;DQ = 1; // 给脉冲信号if(DQ) dat |= 0x80;DS18B20_Delay(4);}return (dat);}/****************************************************************************** *************** 函数名称:DS18B20_Write1Byte()* 功能:向DS18B20写一个字节* 入口参数:dat 要写入DS18B20的一字节数据* 出口参数:无******************************************************************************* **************/void DS18B20_Write1Byte(uchar dat){uchar i = 0;for(i=8;i>0;i--){DQ = 0;DQ = dat&0x01;DS18B20_Delay(5);DQ = 1;dat>>=1;}}/****************************************************************************** *************** 函数名称:Read_Disp_Temperature()* 功能:读取并显示温度* 入口参数:无* 出口参数:无******************************************************************************* **************/double Read_Disp_Temperature(void){uint a = 0, b = 0, c = 0,d = 0,e = 0, t = 0;double tt = 0;DS18B20_Init();DS18B20_Write1Byte(0xCC); // 跳过读序号列号的操作DS18B20_Write1Byte(0x44); // 启动温度转换DS18B20_Init();DS18B20_Write1Byte(0xCC); // 跳过读序号列号的操作DS18B20_Write1Byte(0xBE); // 读取温度寄存器a = DS18B20_Read1Byte();b = DS18B20_Read1Byte();t = b;t <<= 8;t = t | a;//tt = t * 0.0625;return t;}//***************************************************************** //函数名称:delay(uint t)延时函数。
C51单片机和12864液晶显示制作十位简易计算器C源码
#include <reg51.h>#include<intrins.h>#include<math.h>#include<stdlib.h>sbit RS=P2^0;sbit RW=P2^1;sbit E=P2^2;sbit BUZZER=P1^0;#define unchar unsigned char#define unint unsigned intvoid delay(unsigned int t){unsigned int i,j;for(i = 0;i < t;i ++)for(j = 0;j < 120;j ++);}void busy() //判断忙状态{RS=0;RW=1;E=1;P0=0xff;while((P0&0X80)==0x80);_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_(); _nop_();}void write_com( unsigned char com){ _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_(); _nop_();busy();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_(); _nop_();RS=0;RW=0;E=1;P0=com;_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_(); _nop_();E=0;_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_(); _nop_();}void write_date(unchar date){ _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_(); _nop_();busy();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_(); _nop_();RS=1;RW=0;E=1;P0=date;E=0;}void init() //液晶初始化{write_com(0x30); //选择基本指令,选择8位数据流_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_(); _nop_();write_com(0x0c); //开显示(无游标,不反白)0x0e显示游标_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_(); _nop_();write_com(0x01); //清除显示,并且设定地址指针为00H_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_(); _nop_();write_com(0x06);// 设定游标移动方向}void sendaddr(unchar n,unchar m) //送地址{switch(n){case 1:write_com(0x80+m);break;case 2:write_com(0x90+m);break;case 3:write_com(0x88+m);break;case 4:write_com(0x98+m);break;}}void display(unchar n,unchar m,unchar *s) //显示字符串{sendaddr(n,m);while(*s>0){write_date(*s);s++;}void clearscreen() //清屏{write_com(0x01);}void tishi(){clearscreen();display(1,0,"超出计算范围");display(2,0,"请按复位键");display(3,0,"并重新输入");display(4,0,"否则会出现错误");}void displayshu(unchar n,unchar m, long rzt) //显示字符串{ unchar i,j,k,x,p;unchar t[10]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};unsigned char array[10];array[9]=(int)rzt%10;array[8]=((int)rzt/10)%10;array[7]=((int)rzt/100)%10;array[6]=((int)rzt/1000)%10;array[5]=((int)rzt/10000)%10;array[4]=((int)rzt/100000)%10;array[3]=((int)rzt/1000000)%10;array[2]=((int)rzt/10000000)%10;array[1]=((int)rzt/100000000)%10;array[0]=(int)rzt/1000000000;sendaddr(n,m);for(i=0;i<10;i++){if(array[i]==0)p=i;elsebreak;}for(j=p+1;j<10;j++){t[k]=array[j] ;k++;}while(t[x]!=0xff)write_date(t[x]+0x30);x++;}}void main(void){unchar i,j,opt,p;long b,c,rzt;start:init();delay(20);i=0;j=0;rzt=0;b=0;c=0;write_com(0x80);while(1) //输入第一个数{P3=0xfe;if(P3!=0xfe){delay(40);if(P3!=0xfe){switch(P3&0xf0){case0x70:BUZZER=0;delay(80);BUZZER=1;write_date(0+0x30);b=b*10+0;i++;if(i==11)tishi(); break;case0xb0:BUZZER=0;delay(80);BUZZER=1;write_date(1+0x30);b=b*10+1;i++;if(i==11)tishi(); break;case0xd0:BUZZER=0;delay(80);BUZZER=1;write_date(2+0x30);b=b*10+2;i++;if(i==11)tishi(); break;case0xe0:BUZZER=0;delay(80);BUZZER=1;write_date(3+0x30);b=b*10+3;i++;if(i==11)tishi(); break;}if(P3!=0xfe);delay(30);while(P3!=0xfe);}}P3=0xfd;if(P3!=0xfd){delay(40);if(P3!=0xfd){switch(P3&0xf0){case0x70:BUZZER=0;delay(80);BUZZER=1;write_date(4+0x30);b=b*10+4;i++;if(i==11)tishi(); break;case0xb0:BUZZER=0;delay(80);BUZZER=1;write_date(5+0x30);b=b*10+5;i++;if(i==11)tishi(); break;case0xd0:BUZZER=0;delay(80);BUZZER=1;write_date(6+0x30);b=b*10+6;i++;if(i==11)tishi(); break;case0xe0:BUZZER=0;delay(80);BUZZER=1;write_date(7+0x30);b=b*10+7;i++;if(i==11)tishi(); break;}if(P3!=0xfd);delay(30);while(P3!=0xfd);}}P3=0xfb;if(P3!=0xfb){delay(40);if(P3!=0xfb){switch(P3&0xf0){case0x70:BUZZER=0;delay(80);BUZZER=1;write_date(8+0x30);b=b*10+8;i++;if(i==11) tishi(); break;case0xb0:BUZZER=0;delay(80);BUZZER=1;write_date(9+0x30);b=b*10+9;i++;if(i==11) tishi(); break;case0xd0:BUZZER=0;delay(80);BUZZER=1;p=1;write_com(0x97);write_date(0x2b);opt=10; goto two; break;case0xe0:BUZZER=0;delay(80);BUZZER=1;p=1;write_com(0x97);write_date(0x2d);opt=11; goto two; break;}if(P3!=0xfb);delay(30);while(P3!=0xfb);}}P3=0xf7;if(P3!=0xf7){delay(40);if(P3!=0xf7){switch(P3&0xf0){case0x70:BUZZER=0;delay(80);BUZZER=1;p=1;write_com(0x97);write_date(0x2a);opt=12; goto two; break;case0xb0:BUZZER=0;delay(80);BUZZER=1;p=1;write_com(0x97);write_date(0x2f);opt=13; goto two; break;case 0xd0:BUZZER=0;delay(80);BUZZER=1; clearscreen();goto start;break;case 0xe0:BUZZER=0;delay(80);BUZZER=1; clearscreen();goto start;break;}if(P3!=0xf7);delay(30);while(P3!=0xf7);}}}two:write_com(0x88);while(1) //输入第二个数{P3=0xfe;if(P3!=0xfe){delay(40);if(P3!=0xfe){switch(P3&0xf0){case0x70:BUZZER=0;delay(80);BUZZER=1;write_date(0+0x30);c=c*10+0;j++;if(j==11)tishi(); break;case0xb0:BUZZER=0;delay(80);BUZZER=1;write_date(1+0x30);c=c*10+1;j++;if(j==11)tishi(); break;case0xd0:BUZZER=0;delay(80);BUZZER=1;write_date(2+0x30);c=c*10+2;j++;if(j==11)tishi(); break;case0xe0:BUZZER=0;delay(80);BUZZER=1;write_date(3+0x30);c=c*10+3;j++;if(j==11)tishi(); break;}if(P3!=0xfe);delay(30);while(P3!=0xfe);}}P3=0xfd;if(P3!=0xfd){delay(40);if(P3!=0xfd){switch(P3&0xf0){case0x70:BUZZER=0;delay(80);BUZZER=1;write_date(4+0x30);c=c*10+4;j++;if(j==11)tishi();brea k;case0xb0:BUZZER=0;delay(80);BUZZER=1;write_date(5+0x30);c=c*10+5;j++;if(j==11)tishi();brea k;case0xd0:BUZZER=0;delay(80);BUZZER=1;write_date(6+0x30);c=c*10+6;j++;if(j==11)tishi();brea k;case0xe0:BUZZER=0;delay(80);BUZZER=1;write_date(7+0x30);c=c*10+7;j++;if(j==11)tishi();break ;}if(P3!=0xfd);delay(30);while(P3!=0xfd);}}P3=0xfb;if(P3!=0xfb){delay(40);if(P3!=0xfb){switch(P3&0xf0){case0x70:BUZZER=0;delay(80);BUZZER=1;write_date(8+0x30);c=c*10+8;j++;if(j==11)tishi(); break;case0xb0:BUZZER=0;delay(80);BUZZER=1;write_date(9+0x30);c=c*10+9;j++;if(j==11)tishi(); break;case0xd0:BUZZER=0;delay(80);BUZZER=1;if(p==0){ write_com(0x97); write_date(0x2b);} break;case0xe0:BUZZER=0;delay(80);BUZZER=1;if(p==0){ write_com(0x97); write_date(0x2d);} break;}if(P3!=0xfb);delay(30);while(P3!=0xfb);}}P3=0xf7;if(P3!=0xf7){delay(40);if(P3!=0xf7){switch(P3&0xf0){case0x70:BUZZER=0;delay(80);BUZZER=1;if(p==0){ write_com(0x97); write_date(0x2a);} break;case0xb0:BUZZER=0;delay(80);BUZZER=1;if(p==0){ write_com(0x97); write_date(0x2f);} break;case 0xd0:BUZZER=0;delay(80);BUZZER=1;goto answer;break;case 0xe0:BUZZER=0;delay(80);BUZZER=1; clearscreen();goto start;break;}if(P3!=0xf7);delay(30);while(P3!=0xf7);}}}answer:write_com(0x98);write_date(0x3d);if(c==0&&opt==13) //错误处理{display(2,0,"分母不能为零");clearscreen();goto start;}switch(opt){case 10:rzt=(b+c);displayshu(4,2,rzt);break;case 11:rzt=(b-c);if(rzt<0){rzt=c-b;write_date(0x2d);} displayshu(4,2,rzt);break;case 12:rzt=(b*c);displayshu(4,2,rzt);break;case 13:rzt=(b/c);if((int)b%(int)c==0)displayshu(4,2,rzt);elserzt=rzt*1000;displayshu(4,2,rzt);break;}//错误处理与显示if(rzt>9999999999){clearscreen();display(2,1,"超出计算范围");delay(1000);goto start;}while(1){P3=0xf7;if(P3!=0xf7){delay(40);if(P3!=0xf7){if((P3&0xf0)==0xe0){goto start;}if(P3!=0xf7);delay(30);while(P3!=0xf7);}}}}。
51单片机12864万年历(图片+主要程序C语言)
51单片机做的12864万年历这是我花了一个星期时间做的万年历;一开始是一些图片,后面是这个制作的C语言源程序;希望大家稀饭:Main.c#include "reg52.h"#include "macroconst.h"#include "keyscan.h"#include "screen.h"#include "18b20.h"#include "ds1302.h"#include "atao_12864.h"#include "24c02.h"idata unsigned char state1[1];unsigned char screennum=1;//屏幕号#define time_task_sec 200 //节拍200Hz#define clock 24000000 //晶振#define max_task 4 //最大任务数idata unsigned char task_delay[4];#define task_delay0 time_task_sec/1 //2赫兹18b20 #define task_delay1 time_task_sec/5 //10赫兹屏幕#define task_delay2 time_task_sec/3 //4赫兹1302 #define task_delay3 time_task_sec/20 //20赫兹键盘void init(){unsigned char i;init18b20();ds1302_init();initina1(); //---------------------------LCD字库初始化程序RdFromROM(state1,8,1);state[0]=state1[0]; //-------界面RdFromROM(state1,15,1);state[1]=state1[0];//------- 闹钟RdFromROM(state1,11,1);key_sound=state1[0];//-------按键音// state[2]=state1[2];// state[3]=state1[3];screennum=1;//------默认一号屏for(i=0;i<max_task;i++)//清除任务延时{task_delay[i]=0;}TMOD=0x11;EA=1;TH0=255-clock/time_task_sec/12/526;TL0=255-clock/time_task_sec/12%526;ET0=1;TR0=1;}void main(){init();while(1){ if(task_delay[0]==0){readtemp(); task_delay[0]=task_delay0;} if(task_delay[3]==0){MenuCheckKey();task_delay[3]=task_delay1;}if(task_delay[1]==0){screen_select(screennum);task_delay[1]=task_delay1;} if(task_delay[2]==0){ds1302_read_time(); task_delay[2]=task_delay0;} }}void timer0() interrupt 1{uchar i=0;TH0=255-clock/time_task_sec/12/526;TH1=255-clock/time_task_sec/12%526;for(i=0;i<max_task;i++)if(task_delay[i]) task_delay[i]--; // miao=21,fen=33,xiaomiao=94;if(ma_start==1){tt++;if(tt==8){tt=0;xiaomiao++;if(xiaomiao==99){xiaomiao=0;miao++;if(miao==60){miao=0;fen++;if(fen==99){fen=0;}}}}}}Screen.c:#include "reg52.h"#include "macroconst.h"#include "delay.h"#include "18b20.h"#include "atao_12864.h"#include "ds1302.h"#include "24c02.h"#include "festival.h"#include "keyscan.h"idata unsigned char miao=0,fen=78,xiaomiao=0,tt=0;idata unsigned char bai,shi,ge,shinian,genian,shiyue,geyue,shiri,geri,shishi,geshi,shifen,gefen,shimi ao,gemiao;idata unsigned char Number[4];unsigned char code mainmenu[]={" 主菜单""3.查询 4.温度""1.调时 2.秒表""5.设置 6.返回"};unsigned char code setmenu[]={" 设置""3.查温 4.按键""1.界面 2.闹铃""5.报时 6.返回"};void gettime(){shinian=(time_buf1[1]%100)/10;genian=(time_buf1[1]%100)%10;shiyue=(time_buf1[2])/10;geyue=(time_buf1[2])%10;shiri=(time_buf1[3])/10;geri=(time_buf1[3])%10;shishi=(time_buf1[4])/10;geshi=(time_buf1[4])%10;shifen=(time_buf1[5])/10;gefen=(time_buf1[5])%10;shimiao=(time_buf1[6])/10;gemiao=(time_buf1[6])%10;}void screen_select(uchar num){// initina1();gettime() ;if(num==1) //----------主界面{Lcd_Set_Post(1,0);TransferData(shinian+48,1);//----------------------年TransferData(genian+48,1);TransferData('/',1);TransferData(shiyue+48,1);//----------------------月TransferData(geyue+48,1);TransferData('/',1);TransferData(shiri+48,1);//----------------------日TransferData(geri+48,1);Lcd_Set_Post(1,4);if(state[1]==1)//----------------闹铃的状态图标{TransferData(' ',1);TransferData(14,1);}Lcd_Set_Post(1,5);if(key_sound==1){TransferData(13,1);}if(state[0]==0){Lcd_Set_Post(1,7); //----------------农历年nian(0);Lcd_Set_Post(2,0);//----------------------- 农历日月LCD_WRITE_CHAR("农历");Conversion(0,time_buf[1],time_buf[2],time_buf[3]);TransferData(month_moon/16+'0',1);TransferData(month_moon%16+'0',1);TransferData('/',1);TransferData(day_moon/16+'0',1);TransferData(day_moon%16+'0',1);}if(state[0]==1){Lcd_Set_Post(3,5);}else {Lcd_Set_Post(2,5);}LCD_WRITE_CHAR("星期");//----------------------星期if(time_buf1[7]==7) {LCD_WRITE_CHAR("日");}if(time_buf1[7]==6) {LCD_WRITE_CHAR("六");}if(time_buf1[7]==5) {LCD_WRITE_CHAR("五");}if(time_buf1[7]==4) {LCD_WRITE_CHAR("四");}if(time_buf1[7]==3) {LCD_WRITE_CHAR("三");}if(time_buf1[7]==2) {LCD_WRITE_CHAR("二");}if(time_buf1[7]==1) {LCD_WRITE_CHAR("一");}Lcd_Set_Post(3,0);TransferData(shishi+48,1);//----------------------时TransferData(geshi+48,1);TransferData(58,1);TransferData(shifen+48,1);//----------------------分TransferData(gefen+48,1);TransferData(58,1);TransferData(shimiao+48,1);//----------------------秒TransferData(gemiao+48,1);if(state[0]==0){bai=(temph/100); //---------------------------------温度shi=(temph%100)/10;ge=(temph%100)%10;Lcd_Set_Post(3,4);if(zerotemp==0){TransferData(' ',1);TransferData(' ',1);} Lcd_Set_Post(3,5);TransferData(shi+48,1);TransferData(ge+48,1);TransferData('.',1);TransferData(templ+48,1);TransferData(0xa1,1);TransferData(0xe6,1);Lcd_Set_Post(4,0);festival(time_buf[2],time_buf[3],time_buf[4]);//农历}}if(num==3)//----------主菜单{Lcd_Set_Post(1,0);//--------设置显示位置LCD_WRITE_CHAR(mainmenu);}if(num==4)//----------设置菜单{Lcd_Set_Post(1,0);//--------设置显示位置LCD_WRITE_CHAR(setmenu);}if(num==5)//----------时间设置{Lcd_Set_Post(1,2);//--------设置显示位置LCD_WRITE_CHAR("时间设置");Lcd_Set_Post(2,1);TransferData(shinian+48,1);//----------------------年TransferData(genian+48,1);LCD_WRITE_CHAR("年");TransferData(shiyue+48,1);//----------------------月TransferData(geyue+48,1);LCD_WRITE_CHAR("月");TransferData(shiri+48,1);//----------------------日TransferData(geri+48,1);LCD_WRITE_CHAR("日");TransferData(time_buf1[7]+48,1);//---------------星期Lcd_Set_Post(3,2);TransferData(shishi+48,1);//--------------------时TransferData(geshi+48,1);LCD_WRITE_CHAR("时");TransferData(shifen+48,1);//---------------------分TransferData(gefen+48,1);LCD_WRITE_CHAR("分");TransferData(shimiao+48,1);//--------------------秒TransferData(gemiao+48,1);}if(num==6)//----------秒表{uchar shi1,shi2,shi3,ge1,ge2,ge3;Lcd_Set_Post(1,3);//--------设置显示位置LCD_WRITE_CHAR("秒表");Lcd_Set_Post(3,2);shi1=fen/10;ge1=fen%10;TransferData(shi1+48,1);TransferData(ge1+48,1);TransferData(':',1);shi2=miao/10;ge2=miao%10;TransferData(shi2+48,1);TransferData(ge2+48,1);TransferData(':',1);shi3=xiaomiao/10;ge3=xiaomiao%10;TransferData(shi3+48,1);TransferData(ge3+48,1);}if(num==8){Lcd_Set_Post(1,2);//--------农历查询LCD_WRITE_CHAR("温度查询");Lcd_Set_Post(3,0);//--------农历查询LCD_WRITE_CHAR("最高温度"); TransferData(':',1);RdFromROM(Number,0,4);if(Number[3]==0){TransferData('-',1);}Lcd_Set_Post(3,5);TransferData(Number[0]+48,1); TransferData(Number[1]+48,1); TransferData('.',1);TransferData(Number[2]+48,1); TransferData(0xa1,1);TransferData(0xe6,1); Lcd_Set_Post(4,0);//--------农历查询LCD_WRITE_CHAR("最低温度"); TransferData(':',1);RdFromROM(Number,4,4);if(Number[3]==0){TransferData('-',1);}Lcd_Set_Post(4,5);TransferData(Number[0]+48,1); TransferData(Number[1]+48,1); TransferData('.',1);TransferData(Number[2]+48,1); TransferData(0xa1,1);TransferData(0xe6,1); }if(num==9)//----------界面菜单{Lcd_Set_Post(1,2);//--------设置显示位置LCD_WRITE_CHAR("界面选择");Lcd_Set_Post(2,0);TransferData(1+48,1);TransferData('.',1);LCD_WRITE_CHAR("多功能界面");Lcd_Set_Post(3,0);TransferData(2+48,1);TransferData('.',1);LCD_WRITE_CHAR("简洁界面");}。
51单片机驱动显示屏12864
/*-- 文字: 机 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x10,0x10,0xD0,0xFF,0x90,0x10,0x00,0xFE,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,
0x04,0x03,0x00,0xFF,0x00,0x11,0x08,0x04,0x03,0x00,0xFF,0x00,0x03,0x04,0x08,0x00,
/*-- 文字: 辉 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x44,0x58,0xC0,0x7F,0xD0,0x48,0x26,0x22,0xE2,0x3A,0xA2,0x22,0x22,0x2A,0x06,0x00,
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,
/*-- 文字: --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
uchar code hz[]={
/*-- 文字: 邓 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x12,0x22,0x42,0x82,0x62,0x1E,0x00,0x00,0xFE,0x02,0x22,0xDA,0x06,0x00,0x00,
51单片机经典C程序(12864)
/*************************************** 控制器:KS0108* MCU:AT89C5* ,晶体频率:12MHz* 取模方式:纵向字节倒序* CS1和CS2为低电平有效**************************************/#include <reg52.h>#define uchar unsigned char#define uint unsigned int#define LCD_PORT P0#define Left 1#define Right 2sbit LCD_Busy=P0^7;sbit LCD_EN = P1^2;sbit LCD_RS = P1^0;sbit LCD_RW = P1^1;sbit LCD_RST= P1^7;sbit LCD_CS2= P3^6;sbit LCD_CS1= P3^5;uchar DisBuf[32],Page_Num,Clm_Num;code char Table0[]={/*-- 文字: A --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27 ,0x38,0x20,/*-- 文字: B --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11 ,0x0E,0x00,/*-- 文字: C --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10 ,0x08,0x00,/*-- 文字: D --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10 ,0x0F,0x00,/*-- 文字: E --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20 ,0x18,0x00,/*-- 文字: F --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00 ,0x00,0x00,/*-- 文字: G --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E ,0x02,0x00,};code unsigned char Table3[]={/*-- 文字: 天 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x40,0x42,0x42,0x42,0x42,0x42,0xFE,0x42,0x42,0x42,0x42,0x42,0x42 ,0x40,0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x06,0x01,0x02,0x04,0x08,0x10,0x30,0x60 ,0x20,0x00,/*-- 文字: 仙 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x80,0x60,0xF8,0x07,0x02,0xE0,0x00,0x00,0x00,0xFF,0x00,0x00,0x00 ,0xE0,0x00,0x01,0x00,0x00,0x7F,0x00,0x20,0x7F,0x20,0x20,0x20,0x3F,0x20,0x20,0x20 ,0x7F,0x00,/*-- 文字: 妹 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x08,0x88,0x7F,0x0A,0x08,0xF8,0x80,0x88,0x88,0x88,0xFF,0x88,0x88,0x88 ,0x80,0x00,0x40,0x21,0x12,0x0C,0x3A,0x11,0x40,0x30,0x0C,0x03,0xFF,0x06,0x08,0x30 ,0x10,0x00,/*-- 文字: 妹 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x08,0x88,0x7F,0x0A,0x08,0xF8,0x80,0x88,0x88,0x88,0xFF,0x88,0x88,0x88 ,0x80,0x00,0x40,0x21,0x12,0x0C,0x3A,0x11,0x40,0x30,0x0C,0x03,0xFF,0x06,0x08,0x30 ,0x10,0x00};code unsigned char Table4[]={/*-- 文字: 我 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x20,0x20,0x22,0x22,0xFE,0x21,0x21,0x20,0x20,0xFF,0x20,0x22,0xAC,0x20 ,0x20,0x00,0x04,0x04,0x42,0x82,0x7F,0x01,0x01,0x10,0x10,0x08,0x07,0x1A,0x21,0x40 ,0xF0,0x00,/*-- 文字: 好 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x10,0x10,0xF0,0x1F,0x10,0xF0,0x80,0x82,0x82,0x82,0xF2,0x8A,0x86,0x82 ,0x80,0x00,0x80,0x43,0x22,0x14,0x0C,0x73,0x20,0x00,0x40,0x80,0x7F,0x00,0x00,0x00 ,0x00,0x00,/*-- 文字: 想 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x08,0xC8,0x38,0xFF,0x18,0x68,0x08,0x00,0xFE,0x2A,0x2A,0x2A,0x2A,0xFE ,0x00,0x00,0x01,0x40,0x70,0x01,0x38,0x40,0x40,0x44,0x59,0x41,0x41,0x61,0x01,0x09 ,0x30,0x00,/*-- 文字: 你 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x80,0x40,0xF0,0x2C,0x43,0x20,0x98,0x0F,0x0A,0xE8,0x08,0x88,0x28,0x1C ,0x08,0x00,0x00,0x00,0x7F,0x00,0x10,0x0C,0x03,0x21,0x40,0x3F,0x00,0x00,0x03,0x1C ,0x08,0x00};code unsigned char Table5[]={/*-- 调入了一幅图像:C:\Documents and Settings\sammy\桌面\小新.bmp --*//*-- 宽度x高度=64x64 --*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xE0,0xF0 ,0xF8,0x7C,0x3C,0x1E,0x1E,0x8F,0xCF,0xCF,0xCF,0xDF,0x9F,0x9F,0x1F,0x1F,0x3F,0x3E ,0x3E,0x3E,0x7C,0x7C,0x7C,0xF8,0xF8,0xF0,0xE0,0xC0,0x80,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x20,0x10,0x08,0x08,0x1E,0x3F,0x7F,0x03 ,0x00,0x00,0x00,0x06,0x07,0x07,0x03,0x03,0x03,0x0F,0x3F,0x3F,0x7E,0x78,0x78,0x30 ,0x00,0x00,0x00,0x00,0x60,0xE0,0xF0,0x78,0x39,0x39,0x73,0xFE,0x60,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x03,0x04,0x08,0x11,0x08,0x04,0x83,0x80,0x0C,0x92,0xA2,0x44 ,0x22,0x12,0x00,0x00,0x00,0x00,0x00,0x0F,0x30,0x40,0x80,0x80,0x80,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x02,0x02,0x04,0x04,0x04,0x08,0x08,0x08,0x08,0x10,0x10,0x00 ,0x00,0x00,0x00,0x40,0x40,0x80,0x80,0x80,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00 ,0x00,0x60,0x90,0x10,0x20,0x10,0x90,0x60,0x00,0x03,0x04,0x08,0x11,0x08,0x04,0x03 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x0C,0x10 ,0xE0,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x01,0x06,0xF8,0x00,0x00 ,0x00,0x00,0x00,0x01,0x02,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F ,0x7F,0xFF,0xF3,0xF3,0xFE,0xFC,0xFC,0xF8,0xF8,0xF0,0xF0,0xF0,0xE0,0xE0,0xE0,0xE0 ,0xE0,0xE0,0xE4,0xE0,0xE0,0xE0,0x10,0x10,0x10,0x08,0x08,0x04,0x02,0x01,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xD8,0xD8,0xFC ,0xFC,0xFC,0xFD,0xFD,0xFF,0xF7,0xF7,0xF7,0xF7,0xFF,0xFF,0xFF,0xFF,0xF3,0xF7,0xF7 ,0xFF,0xFF,0xFF,0xFD,0xFD,0xFC,0xDC,0xD8,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0 ,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0 ,0xC0,0xC0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF ,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF ,0xFF,0xFF};code uchar Table8[]={/*-- 文字: 相 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x10,0x10,0xD0,0xFF,0x30,0x50,0x90,0x00,0xFE,0x22,0x22,0x22,0x22,0xFE ,0x00,0x00,0x04,0x03,0x00,0xFF,0x00,0x00,0x01,0x00,0xFF,0x42,0x42,0x42,0x42,0xFF ,0x00,0x00,/*-- 文字: 约 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x40,0x60,0x58,0xC7,0x60,0x18,0x40,0x20,0x58,0x8F,0x08,0x08,0x08,0xF8 ,0x00,0x00,0x10,0x32,0x13,0x12,0x0A,0x0A,0x08,0x00,0x00,0x00,0x43,0x80,0x40,0x3F ,0x00,0x00,/*-- 文字: 丛 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x00,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0xFE,0x80,0x00,0x00,0x00 ,0x00,0x00,0x20,0x30,0x2C,0x23,0x20,0x21,0x36,0x2C,0x23,0x20,0x20,0x23,0x26,0x3C ,0x28,0x00,/*-- 文字: 林 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x10,0x10,0x90,0xFF,0x90,0x10,0x00,0x10,0x10,0xD0,0xFF,0x90,0x10,0x10 ,0x10,0x00,0x08,0x06,0x01,0xFF,0x00,0x13,0x08,0x04,0x03,0x00,0xFF,0x01,0x06,0x18 ,0x08,0x00};code uchar Table9[]={/*-- 文字: 浪 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x08,0x30,0x01,0xC6,0x30,0x00,0xFC,0x94,0x95,0x96,0x94,0x94,0xFC,0x00 ,0x00,0x00,0x04,0x04,0xFE,0x01,0x00,0x00,0xFF,0x40,0x21,0x06,0x08,0x34,0x62,0xC2 ,0x40,0x00,/*-- 文字: 漫 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x10,0x20,0x81,0x66,0x00,0xC0,0x5F,0xD5,0x55,0x55,0xD5,0x55,0x5F,0xC0 ,0x00,0x00,0x04,0xFC,0x03,0x00,0x00,0x81,0x85,0x4D,0x55,0x25,0x35,0x4D,0xC5,0x41 ,0x00,0x00,/*-- 文字: 野 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x7E,0x4A,0xFE,0x4A,0x4A,0x7E,0x00,0x42,0x52,0xD2,0x6A,0x46,0xC2 ,0x40,0x00,0x22,0x22,0x22,0x1F,0x12,0x12,0x12,0x00,0x40,0x80,0x7F,0x00,0x00,0x00 ,0x00,0x00,/*-- 文字: 岭 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0xF0,0x00,0xFF,0x00,0xF0,0x40,0x20,0x10,0x2C,0x43,0x04,0x08,0x70 ,0x20,0x00,0x08,0x1F,0x08,0x07,0x04,0x07,0x01,0x05,0x09,0x11,0x29,0x65,0x03,0x01 ,0x00,0x00};void Delay_us(unsigned int DelayTime){while(DelayTime) DelayTime--;}void Delay_x10ms(unsigned char DelayTime) //***************10ms延时**********//{unsigned char i,j,k;for(i=0;i<DelayTime;i++)for(j=0;j<10;j++)for(k=0;k<120;k++) {;}}/*----------------------------------------------------------------------------下面这个函数用于液晶模块的忙信号检测。
51单片机串行12864显示.c
{
CH = 0;
delay(1);
lcdinit();
delay(10);
while(1)
{
Test();
delay(5000);
}
}
* 名称 : write_com()
* 功能 : 写串口指令
* 输入 : cmdcode
* 输出 : 无
***********************************************************************/
void write_com(unsigned char cmdcode)
* 输入 : t
* 输出 : 无
***********************************************************************/
void delay(unsigned int t)
{
unsigned int i,j;
for(i=0; i<t; i++)
* 名称 : hzkdis()
* 功能 : 显示字符串
* 输入 : *s
* 输出 : 无
***********************************************************************/
void hzkdis(unsigned char code *s)
* 名称 : lcdinit()
* 功能 : 初始化函数
* 输入 : cmdcode
* 输出 : 无
***********************************************************************/
基于51单片机的12864液晶画点程序
unsigned char largex,largey,smallx,smally; //将两点横纵坐标按大小存储
unsigned char i;
if(x1 > x2)
{
largex = x1;
smallx = x2;
}
else
{
largex = x2;
smallx = x1;
}
if(y1 > y2)
}else{
DL |= (0x01 << (7 - (k % 8))); //修改该点同时保持其他位不变
}
break;
case 2:
if(k < 8){
DH ^= (0x01 << (7 - k)); //修改该点同时保持其他位不变
}else{
DL ^= (0x01 << (7 - (k % 8))); //修改该点同时保持其他位不变
DH &= ~(0x01 << (7 - k)); //修改该点同时保持其他位不变
}else{ //点在低字节
DL &= ~(0x01 << (7 - (k % 8))); //修改该点同时保持其他位不变
}
break;
case 1:
if(k < 8){
DH |= (0x01 << (7 - k)); //修改该点同时保持其他位不变
com(0x34); //在写GDRAM的地址之前一定要打开扩充指令集
//否则地址写不进去!!
for( j = 0 ; j < 32 ; j++ )
{
com(0x80 + j) ; //写Y坐标
51单片机 c语言 12864 st7920 完美液晶示波器
void lcd_init()
{
delayms(3);
lcd_wcmd(0x30);
delayms(1); //选择基本指令集
lcd_wcmd(0x30); //选择8bit数据流
show_str(" ");
lcd_wcmd(0x98);
show_str(" ");
}
/*------------------清整个GDRAM空间----------------------------*/
void clr_gdram()
{ unsigned char x,y; //1.5s
}
for (i=0;i<8;i++)
{
AD_OUT=1;
AD_CLK=1;
al<<=1;
if (AD_OUT) al|=0x01;
AD_CLK=0;
}
AD_CS=1;
ad=(unsigned int)ah;ad<<=8;ad|=al;
return (ad);
a++;
}
if(a==0)
new_lie[t]=lie[t];
}
}
a=0;
}
void sure_lie() //p=temp
{
uchar a=0;
if(t<8)
{
sure_newlie();
return (0x80+y);
51单片机+12864程序
#include<reg52.h>#include"zifuku.h"#define uchar unsigned char#define uint unsigned intsbit di =P2^0; //指令sbit rw =P2^1; // Write or Read,Hread,Lwrite sbit e =P2^2; // 读写使能sbit cs1=P2^3 // cs1=L,选择左边屏sbit rst=P2^6;// Lcm reset,低有效sbit cs2=P2^4; //cs2=L,选择中间屏sbit cs3=P2^5; // cs3=L,选择右边屏sbit bf =P1^7;sbit res=P1^4;void delay(uint us){while(us--);}void delay1(uint ms){uint i,j;for(i=0;i<ms;i++)for(j=0;j<1000;j++);}void write_com(uchar comm){rw=0;di=0;e=1;P1=comm;e=0;}void write_date(uchar dat){rw=0;di=1;e=1;P1=dat;e=0;}void lat_disp(uchar date1,uchar date2){uchar i,j;cs1=1;cs2=1;write_com(0x3f);for(j=0;j<8;j++){write_com(0xb8+j);write_com(0xc0);write_com(0x40);for(i=0;i<32;i++){write_date(date1);write_date(date2);}}}void vshowcustomrow(uchar ucpage,uchar ucline,uchar width,uchar *uca) {uchar count;if(ucline<64){cs1=1;cs2=0;write_com(0x3f);write_com(0xb8+ucpage);write_com(0xc0);write_com(0x40+ucline);{for(count=0;count<width;count++) write_date(*(uca+count));}}else{cs1=0;cs2=1;write_com(0x3f);write_com(0xb8+ucpage);write_com(0x40);write_com(0x40+ucline-64);for(count=0;count<width;count++) write_date(*(uca+count));}}void vshowonechin(uchar ucpage,uchar ucline,uchar *uca){vshowcustomrow(ucpage,ucline ,16,uca);vshowcustomrow(ucpage+1,ucline,16,uca+16);}void vshowonechar(uchar ucpage,uchar ucline,uchar *uca){vshowcustomrow(ucpage,ucline,8,uca);vshowcustomrow(ucpage+1,ucline,8,uca+8);}void vshowgraph(uchar ucpage,uchar ucline,uchar width,uchar high,uchar *uca) {uchar count;for(count=0;count<high;count++){vshowcustomrow(ucpage+count,ucline,width,uca+count*width);}}/*---------------显示1-----------------*/void disp1 (void){lat_disp(0x00,0x00);vshowonechin(0,0,uca_xiao);vshowonechin(0,16,uca_yun);vshowonechin(0,32,uca_ke);vshowonechin(0,48,uca_ji);vshowonechin(0,64,uca_you);vshowonechin(0,80,uca_xian);vshowonechin(0,96,uca_gong);vshowonechin(0,112,uca_si);vshowonechin(2,0,uca_xiao);vshowonechin(2,16,uca_yun);vshowonechin(2,32,uca_pai);vshowonechin(2,48,uca_ye); vshowonechin(2,64,uca_jing); vshowonechin(2,80,uca_xian1); vshowonechin(2,96,uca_shi); vshowonechin(2,112,uca_ping);vshowonechin(4,16,uca_huan); vshowonechin(4,32,uca_ying); vshowonechin(4,48,uca_ni); vshowonechin(4,64,uca_de); vshowonechin(4,80,uca_jia); vshowonechin(4,96,uca_meng);vshowonechar(6,0,uca_T); vshowonechar(6,8,uca_E); vshowonechar(6,16,uca_L); vshowonechar(6,24,uca_maohao);vshowonechar(6,32,uca_yi); vshowonechar(6,40,uca_san); vshowonechar(6,48,uca_qiu); vshowonechar(6,56,uca_er); vshowonechar(6,64,uca_zero); vshowonechar(6,72,uca_er); vshowonechar(6,80,uca_qiu); vshowonechar(6,88,uca_yi); vshowonechar(6,96,uca_ba); vshowonechar(6,104,uca_ba); vshowonechar(6,112,uca_er);}void disp2(void){ lat_disp(0x00,0x00); vshowgraph(2,32,32,4,uca_Pig); }void lcd_initilize(void){rst=0;delay(50);rst=1;write_com(0x3e);write_com(0x3f);}void main(){lcd_initilize();while(1){disp1();delay1(400);lat_disp(0xff,0x00);delay1(400);disp2();delay1(400);}}#include<reg52.h>unsigned char code uca_xiao[]={/*-- 文字: 小--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x00,0x00,0xC0,0x70,0x20,0x00,0xFF,0x00,0x10,0x20,0xC0,0x80,0x00,0x00,0x00, 0x04,0x02,0x01,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x01,0x07,0x02,0x00, };unsigned char code uca_yun[]={/*-- 文字: 芸--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x04,0x04,0x24,0x24,0x3F,0x24,0x24,0x24,0x24,0x3F,0x24,0x24,0x04,0x04,0x00, 0x01,0x01,0x41,0x61,0x51,0x49,0x47,0x65,0x21,0x21,0x25,0x29,0x71,0x21,0x01,0x00,};unsigned char code uca_ke[]={/*-- 文字: 科--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x10,0x12,0x92,0x72,0xFE,0x51,0x91,0x00,0x22,0xCC,0x00,0x00,0xFF,0x00,0x00,0x00, 0x04,0x02,0x01,0x00,0xFF,0x00,0x04,0x04,0x04,0x02,0x02,0x02,0xFF,0x01,0x01,0x00, };unsigned char code uca_ji[]={/*-- 文字: 技--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x08,0x08,0x88,0xFF,0x48,0x28,0x00,0xC8,0x48,0x48,0x7F,0x48,0xC8,0x48,0x08,0x00,0x01,0x41,0x80,0x7F,0x00,0x40,0x40,0x20,0x13,0x0C,0x0C,0x12,0x21,0x60,0x20,0x00, };unsigned char code uca_you[]={/*-- 文字: 有--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x04,0x84,0x44,0xE4,0x34,0x2C,0x27,0x24,0x24,0x24,0xE4,0x04,0x04,0x04,0x00,0x02,0x01,0x00,0x00,0xFF,0x09,0x09,0x09,0x29,0x49,0xC9,0x7F,0x00,0x00,0x00,0x00, };unsigned char code uca_xian[]={/*-- 文字: 限--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0xFE,0x02,0x32,0x4E,0x82,0x00,0xFE,0x4A,0xCA,0x4A,0x4A,0x4A,0x7E,0x00,0x00,0x00, 0xFF,0x00,0x02,0x04,0x03,0x00,0xFF,0x40,0x20,0x03,0x0C,0x12,0x21,0x60,0x20,0x00, };unsigned char code uca_gong[]={/*-- 文字: 公--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x00,0x80,0x40,0x30,0x0E,0x84,0x00,0x00,0x0E,0x10,0x60,0xC0,0x80,0x80,0x00,0x00,0x01,0x20,0x70,0x28,0x24,0x23,0x31,0x10,0x10,0x14,0x78,0x30,0x01,0x00,0x00, };unsigned char code uca_si[]={/*-- 文字: 司--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x10,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0x12,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x1F,0x04,0x04,0x04,0x04,0x04,0x04,0x0F,0x00,0x20,0x40,0x3F,0x00,0x00, };unsigned char code uca_da[]={/*-- 文字: 大--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x20,0x20,0x20,0x20,0x20,0x20,0xA0,0x7F,0xA0,0x20,0x20,0x20,0x20,0x20,0x20,0x00,0x00,0x80,0x40,0x20,0x10,0x0C,0x03,0x00,0x01,0x06,0x08,0x30,0x60,0xC0,0x40,0x00, };unsigned char code uca_pai[]={/*-- 文字: 牌--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0xFE,0x90,0x90,0x9F,0x10,0x00,0xFE,0x92,0xD3,0xBE,0x92,0x92,0xFE,0x00,0x00, 0x40,0x3F,0x00,0x00,0x7F,0x04,0x04,0x06,0x05,0x04,0xFF,0x04,0x04,0x05,0x04,0x00, };unsigned char code uca_ye[]={/*-- 文字: 液--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x10,0x61,0x06,0xE0,0x18,0x84,0xE4,0x1C,0x84,0x65,0xBE,0x24,0xA4,0x64,0x04,0x00,0x04,0x04,0xFF,0x00,0x01,0x00,0xFF,0x41,0x21,0x12,0x0C,0x1B,0x61,0xC0,0x40,0x00, };unsigned char code uca_jing[]={/*-- 文字: 晶--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x00,0x00,0x00,0x7E,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x7E,0x00,0x00,0x00,0x00, 0x00,0x7F,0x25,0x25,0x25,0x25,0x7F,0x00,0x00,0x7F,0x25,0x25,0x25,0x25,0x7F,0x00, };unsigned char code uca_xian1[]={/*-- 文字: 显--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x00,0x00,0x3E,0x2A,0xEA,0x2A,0x2A,0x2A,0xEA,0x2A,0x3E,0x00,0x00,0x00,0x00, 0x20,0x21,0x22,0x2C,0x20,0x3F,0x20,0x20,0x20,0x3F,0x28,0x24,0x23,0x20,0x20,0x00, };unsigned char code uca_shi[]={/*-- 文字: 示--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x20,0x20,0x22,0x22,0x22,0x22,0xE2,0x22,0x22,0x22,0x22,0x22,0x20,0x20,0x00,0x10,0x08,0x04,0x03,0x00,0x40,0x80,0x7F,0x00,0x00,0x01,0x02,0x0C,0x18,0x00,0x00, };unsigned char code uca_ping[]={/*-- 文字: 屏--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x00,0xFF,0x09,0x49,0x59,0xE9,0x49,0x49,0x49,0xE9,0x59,0x49,0x4F,0x00,0x00, 0x40,0x30,0x0F,0x82,0x42,0x32,0x0F,0x02,0x02,0x02,0xFF,0x02,0x02,0x02,0x02,0x00, };unsigned char code uca_huan[]={/*-- 文字: 欢--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x14,0x24,0x44,0x84,0x64,0x1C,0x20,0x18,0x0F,0xE8,0x08,0x08,0x28,0x18,0x08,0x00, 0x20,0x10,0x4C,0x43,0x43,0x2C,0x20,0x10,0x0C,0x03,0x06,0x18,0x30,0x60,0x20,0x00, };unsigned char code uca_ying[]={/*-- 文字: 迎--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x40,0x41,0xCE,0x04,0x00,0xFC,0x04,0x02,0x02,0xFC,0x04,0x04,0x04,0xFC,0x00,0x00, 0x40,0x20,0x1F,0x20,0x40,0x47,0x42,0x41,0x40,0x5F,0x40,0x42,0x44,0x43,0x40,0x00, };unsigned char code uca_ni[]={/*-- 文字: 你--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x80,0x40,0xF0,0x2C,0x43,0x20,0x98,0x0F,0x0A,0xE8,0x08,0x88,0x28,0x1C,0x08,0x00, 0x00,0x00,0x7F,0x00,0x10,0x0C,0x03,0x21,0x40,0x3F,0x00,0x00,0x03,0x1C,0x08,0x00, };unsigned char code uca_de[]={/*-- 文字: 的--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0xF8,0x8C,0x8B,0x88,0xF8,0x40,0x30,0x8F,0x08,0x08,0x08,0x08,0xF8,0x00,0x00, 0x00,0x7F,0x10,0x10,0x10,0x3F,0x00,0x00,0x00,0x03,0x26,0x40,0x20,0x1F,0x00,0x00, };unsigned char code uca_jia[]={/*-- 文字: 加--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x08,0x08,0x08,0xFF,0x08,0x08,0xF8,0x00,0xF8,0x08,0x08,0x08,0xF8,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x20,0x40,0x3F,0x00,0x7F,0x10,0x10,0x10,0x3F,0x00,0x00, };unsigned char code uca_meng[]={/*-- 文字: 盟--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0xFE,0x92,0x92,0x92,0xFE,0x00,0x80,0x7E,0x2A,0x2A,0x2A,0x2A,0xFE,0x00,0x00, 0x40,0x40,0x7C,0x44,0x44,0x7C,0x46,0x45,0x44,0x7C,0x44,0x45,0x7E,0x41,0x40,0x00, };unsigned char code uca_T[]={/*-- 文字: T --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00, };unsigned char code uca_E[]={/*-- 文字: E --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00, };unsigned char code uca_L[]={/*-- 文字: L --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00, };unsigned char code uca_maohao[]={/*-- 文字: : --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00, };unsigned char code uca_zero[]={/*-- 文字: 0 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,};unsigned char code uca_yi[]={/*-- 文字: 1 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00, };unsigned char code uca_er[]={/*-- 文字: 2 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00, };unsigned char code uca_san[]={/*-- 文字: 3 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00, };unsigned char code uca_s[]={/*-- 文字: 4 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00, };unsigned char code uca_wu[]={/*-- 文字: 5 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00, };unsigned char code uca_liu[]={/*-- 文字: 6 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00, };unsigned char code uca_qi[]={/*-- 文字: 7 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00, };unsigned char code uca_ba[]={/*-- 文字: 8 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00, };unsigned char code uca_qiu[]={/*-- 文字: 9 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00, };unsigned char code uca_Pig[]={0x00,0x80,0x40,0x30,0x08,0x04,0x82,0x81,0x61,0x01,0x12,0x8A,0x89,0x11,0x01,0x05, 0x13,0x09,0x89,0x91,0x01,0x31,0xC2,0x0A,0x04,0x02,0x02,0x02,0x02,0x1C,0xE0,0x00, 0x06,0x05,0xC4,0x32,0x0A,0x05,0x82,0x41,0x20,0x26,0x49,0x50,0x5C,0xAD,0xA6,0xA0, 0x86,0x49,0x50,0x5C,0x8D,0x06,0x80,0x41,0x02,0x02,0x04,0x0C,0x34,0xC8,0x09,0x0E, 0x00,0x00,0x03,0x0C,0x10,0x20,0x43,0x54,0xA8,0xD0,0x90,0x26,0x26,0x40,0x40,0x4C, 0x4C,0x20,0x20,0x90,0x4C,0x03,0x83,0x84,0x40,0x40,0x20,0x30,0x0C,0x03,0x00,0x00,0xE0,0xF0,0xF8,0xDC,0x8E,0x03,0x1F,0x21,0x5C,0xB4,0x34,0x1D,0x0D,0x06,0x0E,0x0E, 0x06,0x0D,0x1D,0x35,0x35,0x1D,0x80,0x40,0x21,0x1F,0x03,0x8E,0xDC,0xF8,0xF0,0xE0} ;//图片。
中文图形12864点阵液晶显示模块与51单片机的并行接口电路及C51程序设计
BF 位 ! 当 BF 为 0 时 !LM3033B *0BR3 才可接收 新的指令或数据 " 在操作时 !LM3033B+0BR3 在单
片机的时钟信号的控制下 ! 数据通过数据线传送给
LM3033B,0BR3 ! 当 LM3033B-0BR3 成功接收 到数据后 ! 转入内部时钟控制 ! 封 锁 I/O 口 缓 冲 器 !
技 术 交 流
}
! 结论
在单片机与液晶的接口中 ! 关键是要满足液晶 的时序要求 * 在软件编程中 ! 关键是要进行正确的初 始化 + 操作及写入显示内容的代码 $ 以上接口电路和 相应的程序已经通过调试 ! 并在实际中得到应用 $ 由
& 2008’ 07- 0041- 04 文章编号 "1006- 6268
中文图形 12864 点阵液晶显示模块与 51 单片机的并行接口电路及 C51 程序设计
李志广 :J;! 李晓泉 L! 淮俊霞 :J; &:Q 河北工业大学应用物理系 ! 天津 L$$:L$%
技 术 交 流
;Q深圳市拓普微科技开发有限公司 ! 深圳 D:<$DX% LQ天津市轻工业设计院 ! 天津 L$$:YL ’
[1]杨应平 , 石城 , 蒋爱湘 , 李振华 . 图形点阵液晶显示 模块与 51 系列单片机的接口设计 [J ]. 现代显示 ! 2006,(5):41- 45. [2]李良成 , 张永顺 , 张璟 . 基于 MSP430 单片机的液
晶显示[J ]. 现代显示 !2007 !(5):32- 33.
其对应关系如表图形显示绘图显示ram提供64x32个位元组的记忆空由扩充指令设定绘图ram位址在更改绘图ram时由扩充指令设定gdram位址先设置垂直位址再设置水平位址连续写入两个位元组的资料来完成垂直与水平的坐标位址再写入两个资料到绘图ram而位址计数器ac会自动加一整个写入绘图ram的步骤如下
51单片机带字库液晶12864ds1302数字时钟c源程序(无按键修改功能)
51单片机+带字库液晶12864+DS1302数字时钟C 源程序(无按键修改功 能)过两天的搜索与调试,在别人程序的基础上,不断修改,终于调试成功了 这个程序。
目前还不能修改时间与日期,只是以预定时间以始。
适用于开发板:51单片机(AT89S52 +带字库液晶12864(ST7920)+DS1302实时时钟)实现功能:简单,数字时钟 +日期(以后会不断完美)。
C 语言源程序如下:#include <reg52.h>#include <intrins.h> #define uchar unsigned char #define uint unsigned int /*DS1302 端 口设置 */sbit SCK=P3A 6;sbit SDA=P3A4;sbit RST = P3A5;bitReadRTC_Flag;/* 12864 端口定义 */ #define LCD_data P0 sbit LCD_RS = P2A4;sbit LCD_RW = P2A5; sbit LCD_EN = P2A 6;//液晶使能控制sbit PSB 二卩2八1; //并口控制 //DS1302 时钟 //DS1302 IO // DS1302 复位 //读DS1302全局变量//带字库液晶 12864数据口// 寄存器选择输入// 液晶读/写控制sbit RES=P2A3;uchar code dis1[] = {"电子设计天地"};// 液晶显示的汉字uchar code dis2[] = {"有志者,事竟成!"};uchar code dis4[] = {'0','1','2','3','4','5','6','7','8','9'};unsigned char temp;#define delayNOP(); {_nop_();_nop_();_nop_();_nop_();};void lcd_pos(uchar X,uchar Y); //确定显示位置unsigned char l_tmpdate[7]={0,7,16,19,10,1,9};〃秒分时日月周年09-10-19 16:07:00code unsigned charwrite_rtc_address[7]={0x80,0x82,0x84,0x86,0x88,0x8a,0x8c}; //秒分时日月周年最低位读写位code unsigned charread_rtc_address[7]={0x81,0x83,0x85,0x87,0x89,0x8b,0x8d};void Write_Ds1302_byte(unsigned char temp);void Write_Ds1302( unsigned char address,unsigned char dat );unsigned char Read_Ds1302 ( unsigned char address );void Read_RTC(void);//read RTCvoid Set_RTC(void); //set RTCvoid InitTIMER0(void);//inital timer0/*******************************************************************//**//* 延时函数 *//* *//******************************************************************* /void delay(unsigned int m) // 延时程序 {unsigned int i,j;for(i=0;i<m;i++)**************************************************//*检查LCD 忙状态*//*lcd_busy 为1时,忙,等待。
LCD12864液晶显示器模块化程序51单片机
LCD12864 液晶显示器模块化程序(51单片机)/**********************lcd12864.h 头文件**********************/#ifndef _LCD12864_H_#define _LCD12864_H_extern void lcd12864_busy(); //忙标志函数extern void led12864_clear();//清屏extern void lcd12864_init(); //初始化函数extern void lcd12864_pxy(unsigned char p,unsigned char x,unsigned char y);//数据的显示位置,p=0左半屏,p=1右半屏,p=2两半屏全选,xy为显示的坐标,第四象限,用正值表示。
extern void lcd12864_zifu(unsigned char p,unsigned char x,unsigned char,unsigned char m);//第m个字符的显示位置,与汉字的定义一样,只是xy的坐标的值应小于等于7.extern void lcd12864_hanzi(unsigned char p,unsigned char x,unsigned char y,unsigned char m);//第m个汉字的显示位置,p=0左半屏,p=1右半屏,p=2两半屏全选,xy为显示的坐标,第四象限,用正值表示,x或y的值都应小于等于3。
m为显示的第m个汉字。
#endif/**********************lcd12864.c 文件**********************/#include;#define uint unsigned int#define uchar unsigned charsbit cs2=P2^0;sbit cs1=P2^1;sbit e=P2^2;sbit rw=P2^3;sbit rs=P2^4;uchar code zifu[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,//,00x00,0x00,0x58,0x38,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//。
12864点阵型驱动程序(51单片机、c语言)
** 功能描述:在液晶显示器上写一个ASCII字符,写之前需要使用setxy()函数确定位置
** 输入参数:uchar ascii:字符对应的ascii码
** 输出参数:
** 返 回 值:
** 作 者:xiwangcumt
** 日 期:
**********************************************************/
** 功能描述:C语言下最精确最简单的延时函数,延时时间为2*t+2(us)
** 输入参数:t-延时时间参数
** 输出参数:
** 返 回 值:
** 作 者:xiwangcumt
** 日 期:
**********************************************************/
void setp(uchar n)
{
switch(n){
case 0: cs1=1;cs2=1; break;
case 1: cs1=1;cs2=0; break;
case 2: cs1=0;cs2=1; break;
default:break;}
}
/*********************************************************
** 输入参数:uchar dat
** 输出参数:
** 返 回 值:
** 作 者:xiwangcumt
** 日 期:
**********************************************************/
基于51单片机控制的液晶显示屏C程序设计
基于51单片机控制的液晶显示屏C程序设计作者:付文莉来源:《硅谷》2013年第05期摘要点阵式LCD不仅可以显示字符、数字,还可以显示各种图形、曲线和汉字。
本文介绍了采用C语言实现对液晶显示器TG12864的控制。
关键词单片机;C语言;TG12864;液晶显示中图分类号:TP271 文献标识码:A 文章编号:1671—7597(2013)031-017-021 TG12864液晶原理1.1 TG12864显示原理点阵式LCD其显示原理是控制LCD点阵中点的亮暗,亮和暗的点阵按一定规律可以组成汉字,组成一幅图形和曲线等。
1.2 TG12864内部结构及相关指令1.2.1 TG12864内部结构TG12864是一种图形点阵液晶显示器,它主要由行驱动器、列驱动器及128×64全点阵液晶显示器组成,有20个外部引脚。
可以由单片机控制显示8×4个16×16点阵汉字。
1.2.2 TG12864相关指令该类液晶显示模块的指令系统比较简单,总共有七种。
1)显示开关指令。
功能:设置屏幕显示开/关,DB0=1,开显示;DB0=0,关显示。
DB7~DB0=0x3f,开显示;DB7~DB0=0x3e,关显示。
2)显示起始行设置。
功能:显示起始行是由Z地址计数器控制的,该命令自动将A0~A5位地址送入Z地址计数器,起始地址可以是0~63范围内任意一行。
Z地址计数器具有循环计数功能,用于显示行扫面同步,当扫描完一行后自动加一。
DB7~DB0=0xc0,显示从0行开始。
3)页设置。
功能:页地址存储在X地址计数器中,A2~A0可表示8页,读写数据对页地址没有影响,除本指令可改变页地址外,复位信号RST可把页地址计数器内容清零。
DB7~DB0=0xb8,显示从0页开始。
4)列地址设置。
功能:列地址存储在Y地址计数器中,读写数据对列地址有影响,在对DDRAM进行读写操作后,Y地址自动加一。
DB7~DB0=0x40,显示从0列开始。
用51单片机控制12864显示数字时钟
用51单片机控制12864显示数字时钟用51单片机控制12864显示数字时钟里面有128564显示汉字的程序,自己研究下,不过是用msp430控制的,你改改端口i就可以了。
#include "msp430x26x.h"#define uchar unsigned char#define uint unsigned int#define iDat 1 //数据标志#define iCmd 0 //指令标志#define LCDb_RS 0x20 //定义四个控制引脚#define LCDb_RW 0x40#define LCDb_E 0x80#define LCDb_RST 0x04#define LCDb_L1 0x80 //第一行的地址#define LCDb_L2 0x90 //第二行的地址#define LCDb_L3 0x88 //第三行的地址#define LCDb_L4 0x98 //第四行的地址#define LCDb_SET_RS P1OUT|=LCDb_RS //四个控制管脚的控制操作#define LCDb_SET_RW P1OUT|=LCDb_RW#define LCDb_SET_E P1OUT|=LCDb_E#define LCDb_SET_RST P8OUT|=LCDb_RST#define LCDb_CLR_RS P1OUT&=~LCDb_RS#define LCDb_CLR_RW P1OUT&=~LCDb_RW#define LCDb_CLR_E P1OUT&=~LCDb_E#define LCDb_CLR_RST P8OUT&=~LCDb_RST#define LCDb_DO P4OUT //输出数据总线端口定义#define LCDb_FUNCTION 0x38 // 液晶模式为8位,2行,5*8字符#define LCDb_BASCMD 0x30 // 基本指令集#define LCDb_CLS 0x01 // 清屏#define LCDb_HOME 0x02 // 地址返回原点,不改变DDRAM 内容#define LCDb_ENTRY 0x06 // 设定输入模式,光标加,屏幕不移动#define LCDb_C2L 0x10 // 光标左移#define LCDb_C2R 0x14 // 光标右移#define LCDb_D2L 0x18 // 屏幕左移#define LCDb_D2R 0x1C // 屏幕又移#define LCDb_ON 0x0C // 打开显示#define LCDb_OFF 0x08 // 关闭显示unsigned char RXData;unsigned char Seg_Data[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x 6f} ; //数码管编码unsigned char Result[5]; //整数转化成字符串,给LCD显示void Delayms(uint MS){uint i,j;for( i=0;i<ms;i++)< bdsfid="104" p=""></ms;i++)<>for(j=0;j<1141;j++);}void Delayus(uint US){uint i;US=US*5/4;for( i=0;i<us;i++);< bdsfid="112" p=""></us;i++);<>}void LCD12864_portini()P1DIR=0xFF;P4DIR=0xFF;P5DIR=0xFF;P8DIR=0xFF;P8OUT |=LCDb_RST;// P1OUT=0xFF;}/*函数名称: LCD12864_sendbyte功能: 向12864液晶写入一个字节数据或者指令*/void LCD12864_sendbyte(uchar DatCmd, uchar dByte) {if (DatCmd == iCmd) //指令操作LCDb_CLR_RS;elseLCDb_SET_RS;LCDb_CLR_RW; //写操作LCDb_SET_E;LCDb_DO = dByte; //写入数据//Delayus(500);Delayms(1);LCDb_CLR_E;}/*函数名称: LCD12864_sendstr功能: 向12864液晶写入一个字符串参数: ptString--字符串指针返回值 : 无*/void LCD12864_sendstr(uchar *ptString)while((*ptString)!='\0') //字符串未结束一直写{LCD12864_sendbyte(iDat, *ptString++);}}/*函数名称: LCD12864_clear功能: 12864液晶清屏参数: 无返回值 : 无*/void LCD12864_clear(void){LCD12864_sendbyte(iCmd,LCDb_CLS);Delayms(2);// 清屏指令写入后,2ms 的延时是很必要的}/*函数名称: LCD12864_gotoXY功能: 移动到指定位置参数: Row--指定的行Col--指定的列返回值 : 无*/void LCD12864_gotoXY(uchar Row, uchar Col){switch (Row) //选择行{case 2:LCD12864_sendbyte(iCmd, LCDb_L2 + Col); break; //写入第2行的指定列case 3:LCD12864_sendbyte(iCmd, LCDb_L3 + Col); break; //写入第3行的指定列case 4:LCD12864_sendbyte(iCmd, LCDb_L4 + Col); break; //写入第4行的指定列default:LCD12864_sendbyte(iCmd, LCDb_L1 + Col); break; //写入第1行的指定列}}/*函数名称: LCD12864_initial功能: 12864液晶初始化*/void LCD12864_initial(void){Delayms(100); // 等待内部复位LCD12864_portini(); //端口初始化LCD12864_sendbyte(iCmd, LCDb_FUNCTION); //功能、模式设定LCD12864_sendbyte(iCmd, LCDb_ON); //打开显示LCD12864_clear(); //清屏LCD12864_sendbyte(iCmd, LCDb_ENTRY); // 输入模式设定}void Int_char(int data){if(data/1000){Result[0]=data/1000+'0';Result[1]=data/100%10+'0';Result[2]=data/10%10+'0';Result[3]=data%10+'0';Result[4]=0;}else if(data/100){Result[0]=data/100+'0';Result[1]=data/10%10+'0';Result[2]=data%10+'0';Result[3]=0;}else if(data/10){Result[0]=data/10%10+'0';Result[1]=data%10+'0';Result[2]=0;}else{Result[0]=data%10+'0';Result[1]=0;}}unsigned char Key_Press(void){P7OUT=0xF0;if((P7IN&0x10)&&(P7IN&0x20)&&(P7IN&0x40)&&(P7IN&0 x80)) return 0x00; else return 0xFF;}unsigned char Get_Keycode(void){while(1)P7OUT=0xFE; //扫描第一列if((P7IN&0x10)==0) return 0;else if((P7IN&0x20)==0) return 4;else if((P7IN&0x40)==0) return 8;else if((P7IN&0x80)==0) return 12;P7OUT=0xFD; //扫描第二列if((P7IN&0x10)==0) return 1;else if((P7IN&0x20)==0) return 5;else if((P7IN&0x40)==0) return 9;else if((P7IN&0x80)==0) return 13;P7OUT=0xFB; //扫描第三列if((P7IN&0x10)==0) return 2;else if((P7IN&0x20)==0) return 6;else if((P7IN&0x40)==0) return 10;else if((P7IN&0x80)==0) return 14;P7OUT=0xF7; //扫描第四列if((P7IN&0x10)==0) return 3;else if((P7IN&0x20)==0) return 7;else if((P7IN&0x40)==0) return 11;else if((P7IN&0x80)==0) return 15;}}void Init_compa(){CACTL1 = CAON+CAREF_2+CARSEL; // Enable Comp, ref = 0.5*Vcc = Vin- CACTL2 = P2CA0; // Pin to CA0P1DIR |= 0x01; // P1.0 = o/p direction(CAOUT - LED) P1SEL |= 0x01; // P1.0 - CAOUT, option select}** 函数名称:初始化函数*/void Init_IIC(void){P3SEL |= 0x06; // Assign I2C pins to USCI_B0UCB0CTL1 |= UCSWRST; // Enable SW resetUCB0CTL0 = UCMST + UCMODE_3 + UCSYNC; // I2C Master, synchronous modeUCB0CTL1 = UCSSEL_2 + UCSWRST; // Use SMCLK, keep SW resetUCB0BR0 = 12; // fSCL = SMCLK/12 = ~100kHzUCB0BR1 = 0;UCB0I2CSA = 0x50; // Slave Address is 048hUCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation IE2 |= UCB0RXIE; // Enable RX interrupt_BIS_SR(GIE);// RXCompare = 0x0; // Used to check incoming data }/** 函数名称:字节写函数*/void EEPROM_Write(unsigned char high_Address,unsigned char low_Address,unsigned char Word){while (UCB0CTL1 & UCTXSTP); // 确定总线空闲UCB0CTL1 |= UCTXSTT + UCTR; // 发送起始位,确定为发送模式UCB0TXBUF = high_Address; // 发送高位地址while((IFG2 & UCB0TXIFG)==0); // 判断是否发送完毕UCB0TXBUF = low_Address; // 发送低位地址while((IFG2 & UCB0TXIFG)==0); // 判断是否发送完毕UCB0TXBUF = Word; // 发送数据while((IFG2 & UCB0TXIFG)==0); // 判断是否发送完毕UCB0CTL1 |= UCTXSTP; // 发送停止位while((UCB0CTL1 & UCTXSTP)==1); // 判断停止位是否发送完毕}/**** 函数名称:字节读函数*/void EEPROM_readmore(){UCB0CTL1 &= ~UCTR; // 确定为读while (UCB0CTL1 & UCTXSTP); // 总线是否空闲UCB0CTL1 |= UCTXSTT; // 发送开始位}/*** 函数名称:字节写函数**/void EEPROM_read(unsigned char high_Address,unsigned char low_Address){while (UCB0CTL1 & UCTXSTP); // Ensure stop condition got sent UCB0CTL1 |= UCTXSTT + UCTR; // 发送起始位,确定为写UCB0TXBUF = high_Address; // 发送地址位高位while((IFG2 & UCB0TXIFG)==0); // 判断是否发送完毕UCB0TXBUF = low_Address; // 发送地址位低位while((IFG2 & UCB0TXIFG)==0); // 判断是否发送完毕UCB0CTL1 &= ~UCTR; // 确定为接收while (UCB0CTL1 & UCTXSTP); //UCB0CTL1 |=UCTXSTT ;while((UCB0CTL1 & UCTXSTT)==1);for(unsigned char i=0x0;i<0x2f;i++); // 延时确定数据已经被发送出去UCB0CTL1 |=UCTXSTP + UCTXNACK; // 发送停止位和NACK 位}/*** 函数名称:接收中断函数**/// USCI_B0 Data ISR#pragma vector = USCIAB0TX_VECTOR__interrupt void USCIAB0TX_ISR(void){RXData = UCB0RXBUF; // Get RX dataInt_char(RXData);LCD12864_gotoXY(2,0); //第2行,第1列显示LCD12864_sendstr(Result);/*key_code[0]=RXData%10+'0';key_code[1]=0;LCD12864_gotoXY(1,0); //第1行,第1列显示LCD12864_sendstr(key_code);*/// __bic_SR_register_on_exit(CPUOFF); // Exit LPM0}void Init_UART(){P3OUT &= ~(BIT4+BIT5+BIT6+BIT7);P3SEL = 0xF0; // P3.4,5,6,7 = USCI_A0 TXD/RXD USCI_A1 TXD/RXDUCA0CTL1 |= UCSSEL_1; // CLK = ACLKUCA0BR0 = 0x03; // 32kHz/9600 = 3.41UCA0BR1 = 0x00; //UCA0MCTL = UCBRS1 + UCBRS0; // Modulation UCBRSx = 3UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine** IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt UCA1CTL1 |= UCSSEL_1; // CLK = ACLKUCA1BR0 = 0x03; // 32kHz/9600 = 3.41UCA1BR1 = 0x00; //UCA1MCTL = UCBRS1 + UCBRS0; // Modulation UCBRSx = 3UCA1CTL1 &= ~UCSWRST; // **Initialize USCI state machine** UC1IE |= UCA1RXIE; // Enable USCI_A0 RX interrupt _BIS_SR(GIE); //使能中断}void Init_ADC(){ADC12CTL0 = SHT0_2 + ADC12ON; // Set sampling time, turn on ADC12 ADC12CTL1 = SHP; // Use sampling timer ADC12IE = 0x01; // Enable interruptADC12CTL0 |= ENC; // Conversion enabledP6DIR &= 0x01; // P6.0, i/pP6SEL |= 0x01; // P6.0-ADC option select_BIS_SR(GIE); //使能中断}void Start_ADC(){ADC12CTL0 |= ADC12SC; // Start convn, software controlled }#pragma vector=USCIAB0RX_VECTOR__interrupt void USCI0RX_ISR(void){while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready? UCA0TXBUF = UCA0RXBUF; // TX -> RXed characterLCD12864_sendbyte(iDat,UCA0RXBUF);}#pragma vector=USCIAB1RX_VECTOR__interrupt void USCI1RX_ISR(void){while (!(UC1IFG&UCA1TXIFG)); // USCI_A0 TX buffer ready? UCA1TXBUF = UCA1RXBUF; // TX -> RXed characterLCD12864_sendbyte(iDat,UCA0RXBUF);//UCA1TXBUF = 'z';}// ADC12 interrupt service routine#pragma vector=ADC12_VECTOR__interrupt void ADC12_ISR (void){int i=ADC12MEM0;Int_char(i);LCD12864_gotoXY(2,0); //第1行,第1列显示LCD12864_sendstr(Result);/*key_code[0] =i/1000+'0';key_code[1] =i/100%10+'0';key_code[2] =i/10%10+'0';key_code[3] =i%10+'0';key_code[4] =0;LCD12864_gotoXY(1,0); //第1行,第1列显示LCD12864_sendstr(key_code);*/}void Init_all(){LCD12864_initial(); //LCD初始化,包含了数码管和LED灯初始化P7DIR=0x0F; //键盘扫描初始化P7REN=0xF0; //输入上下拉电阻使能,输出上下拉不使能P7OUT=0xF0; //输入上拉Init_UART(); //串口初始化Init_compa(); //比较器初始化Init_ADC(); //ADC初始化Init_IIC(); //IIC初始化}void Test_Led(){unsigned char i=0;LCD12864_gotoXY(1,0); //第1行,第1列显示LCD12864_sendstr("1.Test_LED");for(;i<16;i++){P8OUT=0xF0|i;Delayms(50);}}void Test_Seg(){int i;LCD12864_gotoXY(1,0); //第1行,第1列显示LCD12864_sendstr("2.Test_SEG");for(i=0;i<500;i++){//4,3,2,1P1OUT&=~0x02;P1OUT|=0x10|0x08|0x04;P5OUT=Seg_Data[9]; //清楚数码管显示Delayms(1); P1OUT&=~0x04;P1OUT|=0x10|0x08|0x02;P5OUT=Seg_Data[8]; //清楚数码管显示Delayms(1); P1OUT&=~0x08;P1OUT|=0x10|0x04|0x02;P5OUT=Seg_Data[7]; //清楚数码管显示Delayms(1); P1OUT&=~0x10;P1OUT|=0x08|0x04|0x02;P5OUT=Seg_Data[6]; //清楚数码管显示Delayms(1); }P5OUT=0x00; //熄灭所有数码管}void Test_Key(){unsigned char i=0;LCD12864_gotoXY(1,0); //第1行,第1列显示LCD12864_sendstr("3.Test_KEY");LCD12864_gotoXY(2,0); //第2行,第1列显示LCD12864_sendstr("按键:");for(;i<16;i++){Int_char(Get_Keycode());LCD12864_gotoXY(2,3);LCD12864_sendstr(" ");LCD12864_gotoXY(2,3);LCD12864_sendstr(Result);Delayms(100); //防抖}}void Test_Uart(){LCD12864_gotoXY(1,0); //第1行,第1列显示LCD12864_sendstr("4.Test_UART");LCD12864_gotoXY(2,0); //第2行,第1列显示}void Test_Compa(){LCD12864_gotoXY(1,0); //第1行,第1列显示LCD12864_sendstr("5.Test_COMPA");}void Test_ADC(){int i=0;LCD12864_gotoXY(1,0); //第1行,第1列显示LCD12864_sendstr("6.Test_ADC");for(;i<200;i++){Start_ADC();Delayms(10);}}void Test_IIC(){LCD12864_gotoXY(1,0); //第1行,第1列显示LCD12864_sendstr("7.Test_IIC");EEPROM_Write(0x00,0x40,7); // 字节写Delayms(10);EEPROM_read(0x00,0x40);}void main( void ){// Stop watchdog timer to prevent time out resetWDTCTL = WDTPW + WDTHOLD;//关闭看门狗Init_all();while(1){Test_Led(); //1.测试LEDLCD12864_gotoXY(2,0); //第1行,第1列显示LCD12864_sendstr("请按16键!");while(!(Get_Keycode()==15)); //按下最后一键测试下一个例子LCD12864_clear();Test_Seg(); //2.测试数码管LCD12864_gotoXY(2,0); //第1行,第1列显示LCD12864_sendstr("请按16键!");while(!(Get_Keycode()==15)); //按下最后一键测试下一个例子LCD12864_clear();Test_Key(); //3.测试按键扫描LCD12864_gotoXY(2,0); //第1行,第1列显示LCD12864_sendstr("请按16键!");while(!(Get_Keycode()==15)); //按下最后一键测试下一个例子LCD12864_clear();LCD12864_gotoXY(3,0); //第3行,第1列显示LCD12864_sendstr("请按16键!");Test_Uart(); //4.测试串口while(!(Get_Keycode()==15)); //按下最后一键测试下一个例子LCD12864_clear();Test_Compa(); //5.测试比较器LCD12864_gotoXY(2,0); //第2行,第1列显示LCD12864_sendstr("请按16键!");while(!(Get_Keycode()==15)); //按下最后一键测试下一个例子LCD12864_clear();Test_ADC(); //6.测试ADCLCD12864_gotoXY(3,0); //第3行,第1列显示LCD12864_sendstr("请按16键!");while(!(Get_Keycode()==15)); //按下最后一键测试下一个例子LCD12864_clear();Test_IIC(); //7.测试IICDelayms(100);LCD12864_gotoXY(3,0); //第3行,第1列显示LCD12864_sendstr("测试完成");while(!(Get_Keycode()==15)); //按下最后一键测试下一个例子LCD12864_clear();}}。
12864显示程序,51单片机,C语言
12864显示程序,51单片机,C语言可显示固定中文,字符,数字;可实时动态刷新显示数字,字符;#include<reg52.h>sbit rs=P1^2;sbit rw=P1^1;sbit cs=P1^0;sbit psb=P1^3;unsigned char code table[]={" X0: Y0: "}; unsigned char code table1[]={"现在X1: Y1: "}; unsigned char code table2[]={"划线模式:"}; unsigned char code table3[]={"开始暂停"};void delay(unsigned char z) //延时{unsigned i,j;for(i=0;i<z;i++)for(j=0;j<110;j++);}void write_com(unsigned int com) //写命令{rs=0;rw=0;cs=0;P2=com;delay(5);cs=1;delay(5);cs=0;}void write_date(unsigned char dat) //写数据{rs=1;rw=0;cs=0;P2=dat;delay(5);cs=1;delay(5);cs=0;}void pos(unsigned char x,unsigned char y) //起点函数{unsigned char pos;if(x==0)x=0x80;else if(x==1)x=0x90;else if(x==2)x=0x88;else if(x==3)x=0x98;pos=x+y/2;write_com(pos);}void init(){unsigned char i;psb=1; //1并行,0串行write_com(0x30); //基本指令操作delay(5);write_com(0x0c); //显示开,关光标delay(5);write_com(0x01); //清除led的显示内容delay(5);pos(0,0);i=0;while(table[i]!='\0') //第一行固定显示{write_date(table[i]);i++;}pos(1,0);i=0;while(table1[i]!='\0'){write_date(table1[i]); //第二行固定显示i++;}pos(2,0);i=0;while(table2[i]!='\0'){write_date(table2[i]); //第三行固定显示i++;}pos(3,0);i=0;while(table3[i]!='\0'){write_date(table3[i]); //第四行固定显示i++;}}void write_dianya(unsigned char add_x,unsigned char add_y,int date){//12864刷新char bai,shi,ge;bai=date/100;shi=date%100/10;ge=date%10;pos(add_x,add_y);write_date(0x30+bai);write_date(0x30+shi);write_date(0x30+ge);}void main(){init();while(1){write_dianya(0,3,134);}}。
51单片机带字库12864液晶动态汉字显示C语言源程序
51单片机带字库12864液晶动态汉字显示C语言源程序2009-10-17 19:36实验芯片为:AT89S52,带字库液晶屏:12864,实现的目的:动态一个汉字一个汉字显示。
其实和显示汉字的程序一样,只是稍做一下修改即可。
C语言源程序如下:#include <stdio.h>#include <math.h>#include <reg52.h>#include <string.h>sbit RS=P2^4;sbit WRD=P2^5;sbit E=P2^6;sbit PSB=P2^1;sbit RES=P2^3;void TransferData(char data1,bit DI);void delayms(unsigned int n);void delay(unsigned int m);void lcd_mesg003(unsigned char code *addr1);unsigned char code IC_DAT[]={"我是一个中国人啊"};void initinal(void){delay(40);PSB=1; //并口工作模式delay(1);RES=0; //复位delay(1);RES=1; //复位置高delay(10);TransferData(0x30,0);delay(100);TransferData(0x30,0);delay(37);TransferData(0x08,0);delay(100);TransferData(0x10,0);delay(100);TransferData(0x0C,0);delay(100);TransferData(0x01,0);delay(10);TransferData(0x06,0);delay(100);}void main(void){while(1){initinal();//调用LCD字库初始化程序delay(100);lcd_mesg003(IC_DAT);}}void lcd_mesg003(unsigned char code *addr1){unsigned char i;//第一行TransferData(0x80,0);delay(100);for(i=0;i<16;i++){TransferData(*addr1,1);addr1++;delayms(50);}}void TransferData(char data1,bit DI) //传送数据或是命令,当DI=0时,传送命令,当DI=1时,传送数据{WRD=0;RS=DI;delay(1);P0=data1;E=1;delay(1);E=0;}void delayms(unsigned int n){unsigned int i,j;for(i=0;i<n;i++)for(j=0;j<2000;j++);}void delay(unsigned int m){unsigned int i,j;for(i=0;i<m;i++)for(j=0;j<10;j++);}原理就是在显示每个汉字的时候加了一个延时程序,当然可以用定时器来实现,这样的话,不占用CPU处理时间。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
12864显示程序,51单片机,C语言
可显示固定中文,字符,数字;
可实时动态刷新显示数字,字符;
#include<reg52.h>
sbit rs=P1^2;
sbit rw=P1^1;
sbit cs=P1^0;
sbit psb=P1^3;
unsigned char code table[]={" X0: Y0: "}; unsigned char code table1[]={"现在X1: Y1: "}; unsigned char code table2[]={"划线模式:"}; unsigned char code table3[]={"开始暂停"};
void delay(unsigned char z) //延时
{
unsigned i,j;
for(i=0;i<z;i++)
for(j=0;j<110;j++);
}
void write_com(unsigned int com) //写命令
{
rs=0;
rw=0;
cs=0;
P2=com;
delay(5);
cs=1;
delay(5);
cs=0;
}
void write_date(unsigned char dat) //写数据
{
rs=1;
rw=0;
cs=0;
P2=dat;
delay(5);
cs=1;
delay(5);
cs=0;
}
void pos(unsigned char x,unsigned char y) //起点函数{
unsigned char pos;
if(x==0)
x=0x80;
else if(x==1)
x=0x90;
else if(x==2)
x=0x88;
else if(x==3)
x=0x98;
pos=x+y/2;
write_com(pos);
}
void init()
{
unsigned char i;
psb=1; //1并行,0串行
write_com(0x30); //基本指令操作
delay(5);
write_com(0x0c); //显示开,关光标
delay(5);
write_com(0x01); //清除led的显示内容delay(5);
pos(0,0);
i=0;
while(table[i]!='\0') //第一行固定显示{
write_date(table[i]);
i++;
}
pos(1,0);
i=0;
while(table1[i]!='\0')
{
write_date(table1[i]); //第二行固定显示i++;
}
pos(2,0);
i=0;
while(table2[i]!='\0')
{
write_date(table2[i]); //第三行固定显示i++;
}
pos(3,0);
i=0;
while(table3[i]!='\0')
{
write_date(table3[i]); //第四行固定显示
i++;
}
}
void write_dianya(unsigned char add_x,unsigned char add_y,int date)
{//12864刷新
char bai,shi,ge;
bai=date/100;
shi=date%100/10;
ge=date%10;
pos(add_x,add_y);
write_date(0x30+bai);
write_date(0x30+shi);
write_date(0x30+ge);
}
void main()
{
init();
while(1)
{
write_dianya(0,3,134);
}
}。