• / 5
  • 下载费用:10 金币  

基于C8051F020的12864液晶显示.doc

关 键 词:
基于C8051F020的12864液晶显示.doc
资源描述:
/*--------------文件信息--------------------------------------------------------------------------------**文 件 名: 12864屏.C**修 改 人: Helong---------------------------------------------------------------------------------------------------------*/#include #include #include typedef unsigned char uchar; typedef unsigned int uint;uint count=0;uchar sgewei=0;uchar sshiwei=0;uchar mgewei=0;uchar shuzi1=0;uchar shuzi2=0;uchar shuzi3=0;//函数声明void config (void);void LCD_data(unsigned char data_data);void LCD_command(unsigned char com_data);void LCD_Init(void);void Delay1us(unsigned int us);void Delay1ms(unsigned int us);void LCD_BUSY(void);void LCD_shijian(unsigned char out_addr,unsigned char shuzi1,unsigned char shuzi2,unsigned char shuzi3);sbit lcdRW=P3^2; //5引脚sbit lcdE=P3^3;// E或EP 6引脚sbit lcdRS=P3^1; //D/I 4引脚sbit lcdRST=P3^0;//lcd复位 17引脚sbit lcdPSB=P3^4; //15引脚uchar code table1[]="液晶显示测试";uchar counter= 0; // 记录时间-秒/***********************************************************************//* 初始化配置 *//***********************************************************************/void config (void) { //OVERTIME 2-0bit=111 WDTCN = 0xde; //看门狗禁止 WDTCN = 0xad; //看门狗禁止 //交叉开关允许 XBR0=0x28;//交叉开关配置的几种配置方案见Text2XBR1=0x0C;XBR2=0x40; P0MDOUT = 0xFF;P1MDOUT = 0xFF;P2MDOUT = 0xFF;P3MDOUT = 0xFF; P74OUT=0xff; //P4~7口输出方式配置***** EMI0CF=0x13; //EMD2(EMI0CF4)=0,非复用方式; OSCXCN = 0x67;//外部晶振OSCICN = 0x88; //采用内部晶振,频率为 2MHZ}void delay_50us(uint t){uchar j;for(;t>0;t--)for(j=19;j>0;j--);}/***********************************************************************//* 延时子程序 *//***********************************************************************/void Delay1ms(unsigned int us) {uint x,y;for(x=us;x>0;x--)for(y=110;y>0;y--); }//****************************写指令**********************// void LCD_command(unsigned char com_data){lcdRW=0;lcdRS=0;delay_50us(1);P4=com_data;lcdE=1;delay_50us(10);lcdE=0;delay_50us(2);}//****************************写显示数据**********************void LCD_data(unsigned char data_data){lcdRW=0;lcdRS=1;delay_50us(1);P4=data_data;lcdE=1;delay_50us(10);lcdE=0;delay_50us(2);} /********************测忙碌**********************/void LCD_BUSY(){ P74OUT=0x00; lcdRS=0;Delay1us(500); lcdRW=1;Delay1us(500); lcdE=1;Delay1us(500); P4=0xff;Delay1us(500); while(P4&0x80) { lcdE=0;Delay1us(500); lcdE=1;Delay1us(500); } lcdE=1; lcdRW=0; P74OUT=0x03; P4=0xff;}//***************************LCD初始化****************************void LCD_Init(void){Delay1ms(100); LCD_command(0x30);delay_50us(4); LCD_command(0x30);delay_50us(4); LCD_command(0x0c);//开显示屏delay_50us(4); LCD_command(0x01); //清屏指令delay_50us(240); LCD_command(0x06);delay_50us(10);}//***************************shuzi****************************void LCD_shijian(unsigned char out_addr,unsigned char shuzi1,unsigned char shuzi2,unsigned char shuzi3){ unsigned char i=0;LCD_command(out_addr);LCD_data(shuzi1);LCD_data(:);LCD_data(shuzi2);LCD_data(shuzi3);}//-----------------------------------------------------------//T0秒表//-----------------------------------------------------------/***********************T0_init T0初始化***********************************/void T0_init() { TMOD|=0x01; TH0=0x3C; //0x82; TL0=0xBf; //0x35; IE|=0x82; IP|=0x02; TCON|=0x10; }/***********************Timer0_ISR T0中断***********************************/void Timer0_ISR (void) interrupt 1 { TH0=0x3C; TL0=0xBf; count++; if(count==20) { count=0; sgewei++; if(sgewei==(9+1)) { sgewei=0; sshiwei++; if(sshiwei==5+1) { mgewei++; sshiwei=0; } } } } //-----------------------------------------------------------//主函数//-----------------------------------------------------------void main(void){ unsigned char i; config (); T0_init(); LCD_Init(); Delay1ms(500); LCD_command(0x80);for(i=0;i<12;i++){LCD_data(table1[i]);delay_50us(1);}LCD_command(0x90); while(1) { LCD_command(0x02); LCD_shijian(0x88,mgewei,sshiwei,sgewei); Delay1ms(1000); } }
展开阅读全文
  微传网所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。
0条评论

还可以输入200字符

暂无评论,赶快抢占沙发吧。

关于本文
本文标题:基于C8051F020的12864液晶显示.doc
链接地址:https://www.weizhuannet.com/p-11569882.html
微传网是一个办公文档、学习资料下载的在线文档分享平台!

网站资源均来自网络,如有侵权,请联系客服删除!

 网站客服QQ:80879498  会员QQ群:727456886

copyright@ 2018-2028 微传网络工作室版权所有

     经营许可证编号:冀ICP备18006529号-1 ,公安局备案号:13028102000124

收起
展开