液晶点阵显示屏程序设计.doc

上传人:豆**** 文档编号:17638904 上传时间:2022-05-25 格式:DOC 页数:16 大小:332KB
返回 下载 相关 举报
液晶点阵显示屏程序设计.doc_第1页
第1页 / 共16页
液晶点阵显示屏程序设计.doc_第2页
第2页 / 共16页
点击查看更多>>
资源描述

《液晶点阵显示屏程序设计.doc》由会员分享,可在线阅读,更多相关《液晶点阵显示屏程序设计.doc(16页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、【精品文档】如有侵权,请联系网站删除,仅供学习与交流液晶点阵显示屏程序设计.精品文档.液晶点阵显示屏程序设计单片机课程设计报告一、设计题目:液晶点阵显示屏程序设计二、设计要求:1 能进行正常的模拟量采样值显示(温度、压力、电位),并将其显示到液晶面板上。2 LCD将从下到上滚动显示:“江苏大学计算机学院”,然后显示:“2006年单片机课程设计”“液晶点阵显示屏程序设计”“作者姓名、班级、学号”3 改变字库的内容,显示其它汉字。4 改变页地址或列地址,使显示的内容改变位置5 改变滚动显示模式,使显示内容左右、上下滚动;改变参数使滚动速度变化。三、设计思路及实施步骤:(一)设计思路:由于实验指导书

2、中做过液晶显示和模数转换得实验,根据两个实验的功能实现和流程原理进行设计将程序分成三个模块:主函数模块main.c模数转换模块ADC.c液晶显示模块KS0108.c其中让主函数模块做一些初始化和函数调用工作,模数转换模块主要是将温度,压力,点位的值转化为数字量供液晶显示用,液晶显示模块得到模数转换模块传递过来的数字量显示到液晶面板上。(二)系统流程图:1系统主流程图如下:开始主函数模块显示模块模数转换模块2主函数流程图:开始使能比较器1开中断初始化系统时钟钟初始化定时器0初始化IO端口初始化SPI0使能片内参考电压使能DAC3 显示模块流程图开始初始化LCD滚屏显示江苏大学计算机学院读取数字量

3、并显示调用模数转换得到值显示课程设计题目、班级、姓名健值是否1.2.34 模数转换模块流程图开始读取No和模拟量返回温度返回点位结束返回压力No=2?No=3?No=1?(三)系统部程序及功能说明(程序注释部分)#include c8051F020.h#include 液晶点阵显示试验 -128*64,控制器KS0108试验准备:将拨码开关S1和S2置于ON位置.运行此程序,LCD将从下到上滚动显示:“江苏大学计算机学院” 然后交替显示:“2010年单片机课程设计”“液晶点阵显示屏程序设计”“作者姓名、班级、学号” #define LCD_DATA P2#define LCD_RS P30#d

4、efine LCD_RW P31#define LCD_E P32#define LCD_CS1 P33#define LCD_CS2 P34#define LCD_RST P35#define MUX_TEMP0x08#define MUX_VOLT0x01#define MUX_PRESS0x02#define NOSELECT7279 P5 |= 0x80/SPICS4(P57)=1#define SELECT7279 P5 &= (0x80) /SPICS4(P57)=0;#define Set7279DAT HD7279_DAT=1#define Clr7279DAT HD7279_

5、DAT=0#define Set7279CLK HD7279_CLK=1#define Clr7279CLK HD7279_CLK=0void Delay1ms(unsigned char);/*- 宽度x高度=128x64 -*/char code screen=江苏大学计算机学院;/*- 宽度x高度=128x64 -*/char code screen1=2010年单片机课程设计;/*- 宽度x高度=128x64 -*/char code screen2=液晶点阵显示屏程序设计;/*- 宽度x高度=128x64 -*/;char code screen3=作者姓名、班级、学号;#defin

6、e SELECTCS 0/LCDvoid LCD_WaitReady1(void) /判断LCD控制芯片KS0108是否忙LCD_DATA=0xff;_nop_();LCD_CS2=SELECTCS; /片学cs2LCD_RW=1; /读写选择LCD_RS=0; /数据指令选择LCD_E=1; /读写使能while (LCD_DATA&0x80); /等待空闲LCD_CS2=!SELECTCS; void LCD_WaitReady2(void) /判断LCD控制芯片KS0108是否忙LCD_DATA=0xff;_nop_();LCD_CS1=SELECTCS;LCD_RW=1;LCD_RS=

7、0;LCD_E=1;while (LCD_DATA&0x80);LCD_CS1=!SELECTCS;void LCD_WriteCommand1(char ch) /向LCD控制芯片KS0108发送控制命令LCD_WaitReady1();LCD_CS2=SELECTCS;LCD_RW=0;LCD_RS=0;LCD_DATA=ch;LCD_E=1;LCD_E=0;LCD_CS2=!SELECTCS;void LCD_WriteCommand2(char ch)/向LCD控制芯片KS0108发送控制命令LCD_WaitReady2();LCD_CS1=SELECTCS;LCD_RW=0;LCD_

8、RS=0;LCD_DATA=ch;LCD_E=1;LCD_E=0;LCD_CS1=!SELECTCS;void LCD_WriteData1(char ch)/向LCD控制芯片KS0108发送数据命令LCD_WaitReady1();LCD_CS2=SELECTCS;LCD_RW=0; /写LCD_RS=1; /数据、指令LCD_DATA=ch;LCD_E=1; /读写使能LCD_E=0;LCD_CS2=!SELECTCS;void LCD_WriteData2(char ch)/向LCD控制芯片KS0108发送数据命令LCD_WaitReady2();LCD_CS1=SELECTCS;LCD

9、_RW=0;LCD_RS=1;LCD_DATA=ch;LCD_E=1;LCD_E=0;LCD_CS1=!SELECTCS;/*- 文字: 温 -*/char code Wen=;/*- 文字: 度 -*/char code Du=;/*- 文字: 压 -*/char code Ya=;/*- 文字: 力 -*/char code Li=;/*- 文字: 电 -*/char code Dian=;/*- 文字: 位 -*/char code Wei=;void LCD_WriteHZ(char x,char y,char *Dot) /显示16*16点阵汉字char i;for (i=0;i32

10、;i+)if (x+i%16)64) /左半液晶屏显示LCD_WriteCommand1(0xB8+y+i/16); /页数选择LCD_WriteCommand1(0x40+x+i%16); /列数选择LCD_WriteData1(Doti); /一次写一字节else /右半液晶屏显示LCD_WriteCommand2(0xB8+y+i/16);LCD_WriteCommand2(0x40+x-64+i%16);LCD_WriteData2(Doti);/*- 文字: . -*/char code Dot=;/*- 文字: 0 -*/char code Zero=;/*- 文字: 1 -*/c

11、har code One=;/*- 文字: 2 -*/char code Two=;/*- 文字: 3 -*/char code Three=;/*- 文字: 4 -*/char code Four=;/*- 文字: 5 -*/char code Five=;/*- 文字: 6 -*/char code Six=;/*- 文字: 7 -*/char code Seven=;/*- 文字: 8 -*/char code Eight=;/*- 文字: 9 -*/char code Nine=;void LCD_WriteSZ(char x,char y,int num) / 显示8*16点阵数字和

12、点字符 char *Num_Dot; char i; switch (num) /根据需要选择要输出的数字case 0: Num_Dot=Zero; break;case 1: Num_Dot=One; break;case 2: Num_Dot=Two; break;case 3: Num_Dot=Three; break;case 4: Num_Dot=Four; break;case 5: Num_Dot=Five; break;case 6: Num_Dot=Six; break;case 7: Num_Dot=Seven; break;case 8: Num_Dot=Eight; b

13、reak;case 9: Num_Dot=Nine; break;case -1: Num_Dot=Dot; break;for (i=0;i16;i+)if (x+i%8)64)LCD_WriteCommand1(0xB8+y+i/8); 选择地址显示数字LCD_WriteCommand1(0x40+x+i%8);LCD_WriteData1(Num_Doti);elseLCD_WriteCommand2(0xB8+y+i/8);LCD_WriteCommand2(0x40+x-64+i%8);LCD_WriteData2(Num_Doti);void InitLCD(void)/初始化LC

14、Dchar i,j;LCD_RST=0;Delay1ms(1);LCD_RST=1;/复位信号把页地址计数器内容清零LCD_WriteCommand1(0xc0);LCD_WriteCommand2(0xc0);LCD_WriteCommand1(0x3f); /开显示LCD_WriteCommand2(0x3f);for (j=0;j8;j+)/清屏LCD_WriteCommand1(0xB8+j);/清左半屏LCD_WriteCommand1(0x40);for (i=0;i64;i+)LCD_WriteData1(0x00);LCD_WriteCommand2(0xB8+j);/清右半屏

15、LCD_WriteCommand2(0x40);for (i=0;i64;i+)LCD_WriteData2(0x00);void DispBmp(char *buf)/显示一幅位图 int i,j; / if(mode=0) for (j=0;j8;j+)/显示位图 LCD_WriteCommand1(0xB8+j); LCD_WriteCommand1(0x40); /Y地址读写后自动加1 for (i=0;i64;i+) LCD_WriteData1(buf(j*2)*64+i); /左半液晶屏显示 LCD_WriteCommand2(0xB8+j); LCD_WriteCommand2

16、(0x40); for (i=0;i64;i+) LCD_WriteData2(buf(j*2+1)*64+i); /右半液晶屏显示/*void DispBmpUp(char *buf)/显示一幅位图,并上滚int i;DispBmp(buf);for (i = 0; i = 0; i-)Delay1ms(50);LCD_WriteCommand1(0xc0 + i % 64);/设置起始行,实现下滚LCD_WriteCommand2(0xc0 + i % 64);void DispBmpLeft(char *buf) /显示一幅位图,并左滚int i,j,k;for(k = 0; k 128

17、; k+)Delay1ms(30);for (j = 0; j 8; j+)LCD_WriteCommand1(0xB8 + j);LCD_WriteCommand1(0x40);for (i = 0; i 64; i+)LCD_WriteData1(buf(j * 2) * 64 + (i + k)%128);LCD_WriteCommand2(0xB8 + j);LCD_WriteCommand2(0x40);for (i = 0; i 0; k-)Delay1ms(30); for (j = 0; j 8; j+)LCD_WriteCommand1(0xB8+j);LCD_WriteCo

18、mmand1(0x40);for (i = 0; i 64; i+)LCD_WriteData1(buf(j * 2) * 64 + (i + k)%128);LCD_WriteCommand2(0xB8 + j);LCD_WriteCommand2(0x40);for (i = 0; i 64; i+)LCD_WriteData2(buf(j * 2) * 64 + (i + k + 64)%128);void Delay1s(unsigned char T);unsigned int GetADCValue(char No);char GetKeyValue(void);void Wait

19、KeyOff(void);void TestLCD(void) char i,j,buf4,flag,keyvalue; /flag 为小数点输出标志unsigned int w;InitLCD(); DispBmp(screen); /显示第一幅for (i=0;i64;i+)Delay1ms(50);LCD_WriteCommand1(0xc0+i%64);/设置起始行地址,实现向上滚动,第i行数据放在LCD的第一行显示LCD_WriteCommand2(0xc0+i%64);DispBmp(screen1);/显示第二幅图for (i=0;i64;i+)Delay1ms(50);LCD_

20、WriteCommand1(0xc0+i%64);/设置起始行,实现向上滚动LCD_WriteCommand2(0xc0+i%64);DispBmp(screen2); /显示第三幅图for (i=0;i64;i+)Delay1ms(50);LCD_WriteCommand1(0xc0+i%64);/设置起始行,实现向上滚动LCD_WriteCommand2(0xc0+i%64);DispBmp(screen3); /显示第四幅图for (i=0;i64;i+)Delay1ms(50);LCD_WriteCommand1(0xc0+i%64);/设置起始行,实现向上滚动LCD_WriteCom

21、mand2(0xc0+i%64);Delay1ms(10); InitLCD(); LCD_WriteHZ(0 ,0,Wen); /显示参数的中文字 LCD_WriteHZ(16,0,Du); LCD_WriteHZ(0 ,2,Ya); LCD_WriteHZ(16,2,Li); LCD_WriteHZ(0 ,4,Dian); LCD_WriteHZ(16,4,Wei); for(i=0,flag=0;i=(i+1)%3,flag=0) w = GetADCValue(i+1); /获取温度,电压或压力 Delay1ms(250); buf0=(w%10000)/1000; /取出各位上的数值

22、 buf1=(w%1000)/100; buf2=(w%100)/10; buf3=(w%10); if (i=2) /要输出的是电压,需要输出小数点的位置需改变一下 for(j=0;j5;j+) /5个符号输出 if(j=1) LCD_WriteSZ(32+j*8,i*2,-1); /显示数字,参数为-1输出小数点; flag=1; else LCD_WriteSZ(32+j*8,i*2,bufj-flag);/利用flag来控制数据位 else /输出温度和压力数据 for(j=0;j5;j+) if(j=2) LCD_WriteSZ(32+j*8,i*2,-1); /显示数字参数为-1输

23、出小数点; flag=1; else LCD_WriteSZ(32+j*8,i*2,bufj-flag);ADC:unsigned int idata Temp, Press, Volt;unsigned char idata mux_select;sfr16 ADC0 = 0xbe; / ADC0 datavoid init_adc(void)ADC0CN = 0x81; / ADC0 enabled; normal tracking / mode; ADC0 conversions are initiated / on write to AD0BUSY; ADC0 data is / le

24、ft-justifiedREF0CN = 0x07; / enable temp sensor, on-chip VREF, / and VREF output buffermux_select = MUX_TEMP; / CPU on-chip temp sensorAMX0SL = MUX_TEMP; ADC0CF = (SYSCLK/2500000) 3; / ADC conversion clock = 2.5MHz/ADC0CF |= 0x01; / PGA gain = 2EIE2 &= 0x02; / disable ADC0 EOC interruptEIE1 &= 0x04;

25、 / disable ADC0 window compare interrupt/ On-chip temperature/ AN1. 电位器/ AN2. 应变片void read_analog_inputs(void)long temp_long; AD0INT = 0; / clear conversion complete indicator AD0BUSY = 1; / initiate conversion while (AD0INT = 0); / wait for conversion completeswitch (mux_select) /通过每次的调用来获取电压,温度和压力

26、值case MUX_TEMP: temp_long = ADC0 - 42380/2; temp_long = (temp_long * 200L) / 156; Temp=temp_long;AMX0SL = MUX_VOLT;/ Select AIN1 for next readmux_select = MUX_VOLT;break; case MUX_VOLT:temp_long = ADC0;Volt = 24*temp_long/655;AMX0SL = MUX_PRESS;/ Select on-chip temp sensormux_select = MUX_PRESS;brea

27、k;case MUX_PRESS:temp_long = ADC0;temp_long = 24*temp_long/655;Press = temp_long; AMX0SL = MUX_TEMP; mux_select = MUX_TEMP;break;default:AMX0SL = MUX_TEMP;mux_select = MUX_TEMP;break;unsigned int GetADCValue(char No) / 选择调用输出的的是什么值read_analog_inputs(); /获取温度值read_analog_inputs(); /获取压力值read_analog_i

28、nputs(); / 获取电压值switch (No)case 1:return Temp;case 2:return Press;case 3:if (Press10) Press=0;return Volt;test7279sbitHD7279_DAT=P17;sbitHD7279_CLK=P16;void Delay1us(unsigned char T);void Send7279Byte(unsigned char ch)char i;SELECT7279; /置CS低电平 Delay1us(50); /延时50for (i=0;i8;i+)if (ch&0x80)/输出7位到HD7

29、279A的DATA端 Set7279DAT;elseClr7279DAT;Set7279CLK;/置CLK高电平 ch=ch1;/待发数据左移 Delay1us(8); /延时8Clr7279CLK;/置CLK低电平 Delay1us(8); /延时50Clr7279DAT;/发送完毕,DATA端置低,返回 unsigned char Receive7279Byte(void)unsigned char i,ch;ch=0;Set7279DAT;/DATA端置为高电平,输入状态Delay1us(50); /延时50for (i=0;i8;i+)Set7279CLK;/置CLK高电平Delay1

30、us(8); /延时8ch=ch1;/接收数据左移1位if (HD7279_DAT)ch+=1;/接收1位数据Clr7279CLK;/置CLK低电平Delay1us(8); /延时8Clr7279DAT;/接收完毕,DATA端重新置成低电平(输出状态)return ch;char GetKeyValue(void)char KeyValue;if (CPT1CN&0x40) return -1;/无键按下 Send7279Byte(0x15); /发读键盘指令 KeyValue=Receive7279Byte();NOSELECT7279; /置CS高电平 return KeyValue; v

31、oid WaitKeyOff(void)while (!(CPT1CN&0x40);主程序#include c8051f020.h #include void SYSCLK_Init (void) /初始化时钟 int i; / delay counter OSCXCN = 0x67; / start external oscillator with / 18.432MHz crystal for (i=0; i 256; i+) ; / Wait for osc. to start up while (!(OSCXCN & 0x80) ; / Wait for crystal osc. to

32、 settle OSCICN = 0x88; / select external oscillator as SYSCLK / source and enable missing clock / detector/OSCICN = 0x07; /interal 16MHZ#define PRT0CF P0MDOUT#define PRT1CF P1MDOUT#define PRT2CF P2MDOUTvoid PORT_Init (void) XBR0 = 0x07; / Enable SMBus, SPI0, and UART0 XBR1 = 0x00; XBR2 = 0x44; / Ena

33、ble crossbar and weak pull-ups EMI0CF = 0x27; EMI0TC = 0x21; P74OUT = 0xFF; P0MDOUT = 0x15; P1MDOUT |= 0x3C; /P1.2-P1.5推挽输出 P1 &= 0xc3;/P1.2-P1.5=0void SPI0_Init (void) SPI0CFG = 0x07; / data sampled on 1st SCK rising edge / 8-bit data words SPI0CFG|=0xC0;/CKPOL =1; SPI0CN = 0x03; / Master mode; SPI

34、 enabled; flags / cleared SPI0CKR = SYSCLK/2/8000000-1; / SPI clock 8; / set Timer0 to overflow in 1ms TL0 = -SYSCLK/1000; TR0 = 1; / START Timer0 IE|= 0x2; void Timer0_ISR (void) interrupt 1 /每1ms中断一次,中断程序TH0 = (-SYSCLK/1000) 8; TL0 = -SYSCLK/1000;if (Count1ms) Count1ms-;void Delay1ms(unsigned char

35、 T)Count1ms=T;while (Count1ms); /等待中断,然后在中断程序中减一/*void Delay1s(unsigned char T)while (T)Delay1ms(200);Delay1ms(200);Delay1ms(200);Delay1ms(200);Delay1ms(200);T-;/void Test7279(bit LoopFlag);void TestLCD(void);void init_adc(void);/void DispLED(char *buf);void main (void) WDTCN = 0xde; WDTCN = 0xad; /关看门狗SYSCLK_Init (); /初始化时钟Timer0_Init(); /初始化定时器PORT_Init (); /初始化IO口SPI0_Init (); /初始化SPI0 init_adc();CPT1CN|=0x80;/使能比较器1REF0CN = 0x07; /使能片内参考电压DAC0CN |= 0x80;/使能DAC0DAC0H=0;DAC0L=0;EA=1;/开中断 TestLCD(); /执行显示内容四、显示结果及心得体会显示结果:开始能把显示“江苏大学计算机学院”,然后显示:“2006年单片机课程设计”“液晶点阵显示屏

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 小学资料

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁