lcd 12864液晶

这篇博客介绍了LCD12864液晶显示器的原理和使用方法,包括液晶的页面和列地址设置,以及如何在ATmega8L环境下进行点阵画点操作。提供了详细的初始化、状态检测、写命令和数据的函数,并附带了Proteus6.7的仿真示例,适合初学者学习。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前一段时间想搞一下点阵LCD,于是就到本网站上寻找,找到了好多资料,xiaotanlan朋友的资料很好,http: //www.ouravr.com/bbs/bbs_content.jsp?bbs_sn=468165&bbs_page_no=1&sub_kind_id=2065&bbs_id=1000
但是看了已后,觉得自已做的时候还是有很多要注意的地方.于是就写了下面的内容:

LCD12864液晶说明(个人跟椐datasheet的理解):
  lcd12864分为左半屏和右半屏,每半个屏幕竖着排列着64(0~63)个字节,每个字节最低位在最上面,高位在最下面,一个字节的8位构成了lcd12864一页中一列的8个点,而它共有8页,即在y方向有8*8=64个点.如下图:

画点的重点:
    1,通过x坐标所属的左右半屏.
    2,通过y坐标算出点所属的页,及一页内y坐标(即一个字节中一位的位置).
    3,读出原来要画点位字节内容,再设要画的点(否则会擦除原来画的点).
程序如下:
环境:ATmega8L, WinAVR GCC, LCD12864, Proteus6.7
/*
        ATmega8L LCD12864
        作者:zhb2000
*/
#include <avr/io.h>
#define uchar unsigned char
#define uint  unsigned int
#define bool  unsigned char
#define true  1
#define false 0
#define setbit(sfr,bit) (sfr|=(1<<bit))
#define clrbit(sfr,bit) (sfr&=~(1<<bit))
#define RS   0
#define RW   1
#define CS1  2
#define CS2  3
#define E    4
#define RST  5
#define DATA PORTB
#define CTRL PORTC

void i

DS1302 LCD12864 时钟加adc转换,LED时钟加按钮调时间。代码及仿真 #include<reg51.h> #include <intrins.h> #define u_char unsigned char #include"ds1302.h" #include"lcd.h" #include"main.h" #include"adc.h" u_char judge_year(u_char); u_char count_week(u_char year,u_char month,u_char day); unsigned char code black_write[]= { 0xFF,0x1F,0xEF,0xF7,0xF7,0xEF,0x1F,0xFF,0xFF,0xF0,0xEF,0xDF,0xDF,0xEF,0xF0,0xFF, 0xFF,0xEF,0xEF,0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xDF,0xDF,0xC0,0xDF,0xDF,0xFF,0xFF, 0xFF,0x8F,0xF7,0xF7,0xF7,0x77,0x8F,0xFF,0xFF,0xCF,0xD7,0xDB,0xDD,0xDE,0xCF,0xFF, 0xFF,0xCF,0xF7,0x77,0x77,0xB7,0xCF,0xFF,0xFF,0xE7,0xDF,0xDF,0xDF,0xEE,0xF1,0xFF, 0xFF,0xFF,0x3F,0xDF,0xEF,0x07,0xFF,0xFF,0xFF,0xF8,0xFB,0xDB,0xDB,0xC0,0xDB,0xFF, 0xFF,0x07,0xF7,0x77,0x77,0xF7,0xF7,0xFF,0xFF,0xE6,0xDE,0xDF,0xDF,0xEE,0xF1,0xFF, 0xFF,0x1F,0xEF,0x77,0x77,0xE7,0xFF,0xFF,0xFF,0xF0,0xEE,0xDF,0xDF,0xEE,0xF1,0xFF, 0xFF,0xC7,0xF7,0xF7,0x37,0xC7,0xF7,0xFF,0xFF,0xFF,0xFF,0xC0,0xFF,0xFF,0xFF,0xFF, 0xFF,0x8F,0x77,0xF7,0xF7,0x77,0x8F,0xFF,0xFF,0xE3,0xDD,0xDE,0xDE,0xDD,0xE3,0xFF, 0xFF,0x1F,0xEF,0xF7,0xF7,0xEF,0x1F,0xFF,0xFF,0xFF,0xCE,0xDD,0xDD,0xEE,0xF0,0xFF}; sbit k1=P3^4; sbit k2=P3^5; sbit k3=P3^6; sbit k4=P3^7; sbit k=P3^2; int int_count=0; int ret=0; int stop=0; int main() { int i,temp,j=0;u_char dat[7];u_char adc_data0,adc_data1,adc_data; u_char date[]={0,59,21,28,9,7,14};//秒分时日月周年 u_char time[14]; init_lcd(); IT0=1; EX0=1; IP=0x01; for(i=0;i<7;i++) { temp=date[i]/10; date[i]=date[i]; date[i]=temp*16+date[i]; } write_data(0x8e,0x00);//什么意思?? for(i=0;i<7;i++) write_data(reg_write_address[i],date[i]); TMOD|=0x01; TH0=0xB0;//设初值 TL0=0x3C;//设初值 ET0=1; //中断位置高 EA=1; //开中断 TR0=1; //启动中断 while(1){ if(flag==1) { flag=0; j=0; for(i=0;i<7;i++){ dat[i]=read_data(reg_read_address[i]); //什么意思? time[j++]=dat[i]&0xf; time[j++]=dat[i]/16; } display(0,0,tim+time[13]*16,8); display(0,8,tim+time[12]*16,8); display(0,16,year,16); display(0,32,tim+time[9]*16,8); display(0,40,tim+time[8]*16,8); display(0,48,year+32,16); display(0,64,tim+time[7]*16,8); display(0,72,tim+time[6]*16,8); display(0,80,year+64,16); display(2,0,week,16); display(2,16,week+32,16); display(2,32,digtal+(time[10]-1)*32,16); i=5; for(j=7;j>=0;j--) //什么意思 ? { if(j!=2&&j!=5) display(4,(7-j)*8,tim+time[i--]*16,8); else{ if(flash==0) display(4,(7-j)*8,tim+10*16,8); else if(flash==1) display(4,(7-j)*8,tim+11*16,8); } } /************************************** AD转换 AD转换有什么用? *************************************/ adc_data=read_adc_data(); adc_data0=(adc_data*5)/255; adc_data1=((adc_data*5)%255)*10/255; for(j=0;j<4;j++) display(4,72+(j*8),v+j*16,8); display(4,104,tim+adc_data0*16,8); display(4,112,v+4*16,8); display(4,120,tim+adc_data1*16,8); } while(ret!=0); } } void time0() interrupt 1 { count++; TH0=0xB0; TL0=0x3C; if(count==20){ flash=~flash; count=0; flag=1; } } void interrupt0() interrupt 0 //此中断函数全部调节时间,是这个程序的精华,本来想分开,但是那样会带来的开销大,所以全写在了一起; { int i;u_char temp,t1,t2,year=0,leap_year,week,day; t1=temp_time[6]/16; t2=temp_time[6]&0xf; leap_year=t1*10+t2; day=(temp_time[3]/16)*10+(temp_time[3]&0xf); if(k1==0){ if(stop==0) { ret++; for(i=0;i<7;i++) temp_time[i]=read_data(reg_read_address[i]);} int_count++; stop++; if(k1==0&&int_count==1) { t1=temp_time[0]/16; t2=temp_time[0]&0xf; display(4,48,tim+t1*16,8); display(4,56,tim+t2*16,8); t1=temp_time[6]/16; t2=temp_time[6]&0xf; display(0,0,black_write+t1*16,8); display(0,8,black_write+t2*16,8); } else if(k1==0&&int_count==2) { t1=temp_time[6]/16; t2=temp_time[6]&0xf; display(0,0,tim+t1*16,8); display(0,8,tim+t2*16,8); t1=temp_time[4]/16; t2=temp_time[4]&0xf; display(0,32,black_write+t1*16,8); display(0,40,black_write+t2*16,8); } else if(k1==0&&int_count==3) { t1=temp_time[4]/16; t2=temp_time[4]&0xf; display(0,32,tim+t1*16,8); display(0,40,tim+t2*16,8); t1=temp_time[3]/16; t2=temp_time[3]&0xf; display(0,64,black_write+t1*16,8); display(0,72,black_write+t2*16,8); } else if(k1==0&&int_count==4) { t1=temp_time[3]/16; t2=temp_time[3]&0xf; display(0,64,tim+t1*16,8); display(0,72,tim+t2*16,8); t1=temp_time[2]/16; t2=temp_time[2]&0xf; display(4,0,black_write+t1*16,8); display(4,8,black_write+t2*16,8); } else if(k1==0&&int_count==5) { t1=temp_time[2]/16; t2=temp_time[2]&0xf; display(4,0,tim+t1*16,8); display(4,8,tim+t2*16,8); t1=temp_time[1]/16; t2=temp_time[1]&0xf; display(4,24,black_write+t1*16,8); display(4,32,black_write+t2*16,8); } else if(k1==0&&int_count==6) { t1=temp_time[1]/16; t2=temp_time[1]&0xf; display(4,24,tim+t1*16,8); display(4,32,tim+t2*16,8); temp=read_data(0x81); t1=temp_time[0]/16; t2=temp_time[0]&0xf; display(4,48,black_write+t1*16,8); display(4,56,black_write+t2*16,8); } else if(int_count==7) int_count=0; } else if(k2==0||k3==0) { if(int_count==1)//调节年 { t1=temp_time[6]/16; t2=temp_time[6]&0xf; if(k2==0) temp_time[6]=t1*10+t2+1; else temp_time[6]=t1*10+t2-1; if(temp_time[6]==-1) temp_time[6]=0; leap_year=temp_time[6]; if(temp_time[4]==2) { year=judge_year(leap_year); if(year==0&&day>28){ temp_time[3]=40; display(0,64,tim+(temp_time[3]/16)*16,8); display(0,72,tim+(temp_time[3]&0xf)*16,8); } } temp_time[5]=week=count_week(leap_year,temp_time[4],(temp_time[3]/16)*10+(temp_time[3]&0xf)); t1=temp_time[6]/10; t2=temp_time[6]; temp_time[6]=t1*16+t2; display(0,0,black_write+(temp_time[6]/16)*16,8); display(0,8,black_write+(temp_time[6]&0xf)*16,8); display(2,32,digtal+(temp_time[5]-1)*32,16); } else if(int_count==2)//调节月 { t1=temp_time[4]/16; t2=temp_time[4]&0xf; if(k2==0) temp_time[4]=t1*10+t2+1; else temp_time[4]=t1*10+t2-1; if(temp_time[4]<1) temp_time[4]=1; if(temp_time[4]==13) temp_time[4]=1; else if(temp_time[4]==2){ year=judge_year(leap_year); if(year==0&&day>28) temp_time[3]=40; else if(year==1&&day>29) temp_time[3]=41; display(0,64,tim+(temp_time[3]/16)*16,8); display(0,72,tim+(temp_time[3]&0xf)*16,8); } else if(temp_time[4]==4||temp_time[4]==6||temp_time[4]==9||temp_time[4]==11) { if(day>30) temp_time[3]=48; display(0,64,tim+(temp_time[3]/16)*16,8); display(0,72,tim+(temp_time[3]&0xf)*16,8); } t1=temp_time[4]/10; t2=temp_time[4]; temp_time[4]=t1*16+t2; week=count_week(leap_year,temp_time[4],(temp_time[3]/16)*10+(temp_time[3]&0xf)); temp_time[5]=week; display(0,32,black_write+(temp_time[4]/16)*16,8); display(0,40,black_write+(temp_time[4]&0xf)*16,8); display(2,32,digtal+(temp_time[5]-1)*32,16); } else if(int_count==3)//调节日 { if(temp_time[4]==2){ year=judge_year(leap_year); } t1=temp_time[3]/16; t2=temp_time[3]&0xf; if(k2==0) temp_time[3]=t1*10+t2+1; else temp_time[3]=t1*10+t2-1; if(temp_time[3]<1) temp_time[3]=1; if(year==1&&temp_time[4]==2&&temp_time[3]==30) temp_time[3]=29; else if(year==0&&temp_time[4]==2&&temp_time[3]==29) temp_time[3]=28; else if(temp_time[4]==4||temp_time[4]==6||temp_time[4]==9||temp_time[4]==17) { if(temp_time[3]==31) temp_time[3]=30; } else if(temp_time[3]==32) temp_time[3]=31; week=count_week(leap_year,temp_time[4],temp_time[3]); temp_time[5]=week; t1=temp_time[3]/10; t2=temp_time[3]; temp_time[3]=t1*16+t2; display(0,64,black_write+(temp_time[3]/16)*16,8); display(0,72,black_write+(temp_time[3]&0xf)*16,8); display(2,32,digtal+(temp_time[5]-1)*32,16); } else if(int_count==4)//调节小时 { t1=temp_time[2]/16; t2=temp_time[2]&0xf; if(k2==0) temp_time[2]=t1*10+t2+1; else temp_time[2]=t1*10+t2-1; if(temp_time[2]<0) temp_time[2]=0; if(temp_time[2]>23) temp_time[2]=0; t1=temp_time[2]/10; t2=temp_time[2]; temp_time[2]=t1*16+t2; display(4,0,black_write+(temp_time[2]/16)*16,8); display(4,8,black_write+(temp_time[2]&0xf)*16,8); } else if(int_count==5) { t1=temp_time[1]/16; t2=temp_time[1]&0xf; if(k2==0) temp_time[1]=t1*10+t2+1; else temp_time[1]=t1*10+t2-1; if(temp_time[1]<0) temp_time[1]=0; if(temp_time[1]>59) temp_time[1]=0; t1=temp_time[1]/10; t2=temp_time[1]; temp_time[1]=t1*16+t2; display(4,24,black_write+(temp_time[1]/16)*16,8); display(4,32,black_write+(temp_time[1]&0xf)*16,8); } else if(int_count==6) { t1=temp_time[0]/16; t2=temp_time[0]&0xf; if(k2==0) temp_time[0]=t1*10+t2+1; else temp_time[0]=t1*10+t2-1; if(temp_time[0]<0) temp_time[0]=0; if(temp_time[0]>23) temp_time[0]=0; t1=temp_time[0]/10; t2=temp_time[0]; temp_time[0]=t1*16+t2; display(4,48,black_write+(temp_time[0]/16)*16,8); display(4,56,black_write+(temp_time[0]&0xf)*16,8); } } else if(k4==0) { for(i=0;i<7;i++) write_data(reg_write_address[i],temp_time[i]); ret=0; stop=0; int_count=0; } } u_char judge_year(u_char y)//判断是否是润年 { int year=2000+(int)y; if(year%4==0&&year0!=0) return 1; else if(year0==0&&year%400==0) return 1; else return 0; } u_char count_week(u_char year,u_char month,u_char day)//计算周几的函数 { u_char t1,t2,week; t1=month/16; t2=month&0xf; month=t1*10+t2; week=year+(year/4)+(20/4)-2*20+(26*(month+1)/10)+day-1; week=week%7; if(week==0) week=7; return week; }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值