《毕业设计点阵式液晶显示屏的显示程序设计单片机课程设计报告.doc》由会员分享,可在线阅读,更多相关《毕业设计点阵式液晶显示屏的显示程序设计单片机课程设计报告.doc(32页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、J I A N G S U U N I V E R S I T Y单片机原理及应用课程设计学院名称: 计算机科学与通信工程 专业班级: 通信1002 学生姓名: 马彩霞 学生学号: 3100601033 指导教师姓名: 赵念强 2013年 1 月点阵式液晶显示屏的显示程序设计一、设计目的1熟练掌握C51系统仿真开发系统的应用。2加强单片机的综合运用能力、提高单片机的软件编程和调试能力,为以后的学习和开发工作打下良好基础。3掌握的液晶的工作原理以及应用设计。4掌握小系统开发设计的流程以及设计思路。二、设计方案 实验要求:1)从下到上左到右滚动显示:自己设计的图片 2)能进行正常的模拟量采样值显示
2、(温度、压力、电位) 。3)未按键时菜单要可以停下来 设计思路:由于实验指导书中做过液晶显示和模数转换得实验,根据两个实验的功能实现和流程原理进行设计将程序分成四个模块:主函数模块main.c模数转换模块ADC.c液晶显示模块KS0108.c按键调试模块Test7179.c其中让主函数模块做一些初始化和函数调用工作,模数转换模块主要是将温度,压力,点位的值转化为数字量供液晶显示用,液晶显示模块得到模数转换模块传递过来的数字量显示到液晶面板上,按键调试模块是输入按键显示温度,电压,压力等。程序流程图:1系统主流程图如下开始主函数模块显示模块模数转换模块2主函数流程图开始使能比较器1开中断初始化系
3、统时钟钟初始化定时器0初始化IO端口初始化SPI0使能片内参考电压使能DAC3 显示模块流程图开始初始化LCD滚屏显示江苏大学计算机学院读取数字量并显示调用模数转换得到值显示课程设计题目、班级、姓名健值是否1.2.34 模数转换模块流程图开始读取No和模拟量返回温度返回点位结束返回压力No=2?No=3?No=1? 主要的源程序及注释主函数:#include c8051f020.h #include void Delay1us(unsigned char us) while (us) _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); -us; void
4、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 settle OSCICN = 0x88; / select external oscillator as SYSCLK / source and enable missi
5、ng clock / detector / OSCICN = 0x07; file:/interal 16MHZ #define PRT0CF P0MDOUT #define PRT1CF P1MDOUT #define PRT2CF P2MDOUT void PORT_Init (void) XBR0 = 0x07; / Enable SMBus, SPI0, and UART0 XBR1 = 0x00; XBR2 = 0x44; / Enable crossbar and weak pull-ups EMI0CF = 0x27; EMI0TC = 0x21; P74OUT = 0xFF;
6、P0MDOUT = 0x15; P1MDOUT |= 0x3C; /P1.2-P1.5推挽输出 P1 &= 0xc3; /P1.2-P1.5=0 void 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 enabled; flags / cleared SPI0CKR = SYSCLK/2/8000000-1; / SPI clock 8; /
7、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 T) Count1ms=T; while (Count1ms); void Delay1s(unsigned char T) while (T) Delay1
8、ms(200); Delay1ms(200); Delay1ms(200); Delay1ms(200); Delay1ms(200); T-; char GetKeyValue(void); void init_adc(void); unsigned int GetADCValue(char No); void TestLCD(void); void DispLCD(char *DispBuf,char num); void InitLCD(void); /初始化LCD void ShowWenDu(void); void Test7279(bit LoopFlag) ;void main
9、(void) unsigned int w; char No,i,buf5; No=1; WDTCN = 0xde; WDTCN = 0xad; /关看门狗 SYSCLK_Init (); / 初始化时钟Timer0_Init();/初始化定时器 PORT_Init (); /初始化IO口 SPI0_Init (); /初始化SPI0 init_adc(); CPT1CN|=0x80; /使能比较器1 REF0CN = 0x07; /使能片内参考电压 DAC0CN |= 0x80; /使能DAC0 DAC0H=0; DAC0L=0; EA=1; /开中断/Test7279(0); loop:
10、Test7279(0) ;/关闭数码关显示 TestLCD(); InitLCD(); No=0; /w = GetADCValue(1); for (;) i=GetKeyValue(); if (i=0)&(i=3) No=i; switch(No) case 1: ShowWenDu();break; case 2: ShowDianYa();break; case 3: ShowYaLi();break; case 0:goto loop;break; default: break; w = GetADCValue(No); Delay1ms(30); switch(No) case
11、1: buf0=(w%10000)/1000; buf1=(w%1000)/100; buf2= ; buf3=(w%100)/10; buf4=(w%10); DispLCD(buf,1); showdu(); break; case 2: buf0=(w%10000)/1000; buf1=(w%1000)/100; buf2= ; buf3=(w%100)/10; buf4=(w%10); DispLCD(buf,2); showfu(); break; case 3: buf0=(w%10000)/1000; buf1=(w%1000)/100; buf2= ; buf3=(w%100
12、)/10; buf4=(w%10); DispLCD(buf,3); showniu(); break; default: break; 模数转换#include c8051F020.h #include /* 压力应变片ADC实验*/ #define MUX_TEMP 0x08 #define MUX_VOLT 0x01 #define MUX_PRESS 0x02 unsigned int idata Temp, Press, Volt;unsigned char idata mux_select; sfr16 ADC0 = 0xbe; / ADC0 data void init_adc(
13、void) ADC0CN = 0x81; / ADC0 enabled; normal tracking / mode; ADC0 conversions are initiated / on write to AD0BUSY; ADC0 data is / left-justified REF0CN = 0x07; / enable temp sensor, on-chip VREF, / and VREF output buffer mux_select = MUX_TEMP; / CPU on-chip temp sensor AMX0SL = MUX_TEMP; ADC0CF = (S
14、YSCLK/2500000) 3; / ADC conversion clock = 2.5MHz /ADC0CF |= 0x01; / PGA gain = 2 EIE2 &= 0x02; / disable ADC0 EOC interrupt EIE1 &= 0x04; / disable ADC0 window compare interrupt / On-chip temperature / AN1. 电位片/ AN2. 应变片void read_analog_inputs(void) long temp_long; AD0INT = 0; / clear conversion co
15、mplete indicator AD0BUSY = 1; / initiate conversion while (AD0INT = 0); / wait for conversion complete switch (mux_select) case MUX_TEMP: temp_long = ADC0 - 42380/2; temp_long = (temp_long * 200L) / 156; Temp=temp_long; AMX0SL = MUX_VOLT; / Select AIN1 for next read mux_select = MUX_VOLT; break; cas
16、e MUX_VOLT: temp_long = ADC0; Volt = 24*temp_long/655; AMX0SL = MUX_PRESS; / Select on-chip temp sensor mux_select = MUX_PRESS; break; 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_s
17、elect = MUX_TEMP; break; unsigned int GetADCValue(char No) read_analog_inputs(); read_analog_inputs(); read_analog_inputs(); switch (No) case 1: return Temp; case 2: return Volt; case 3: if (Press10) Press=0; return Press; 液晶显示模块KS0108.c#include C8051F020.h #include /* 液晶点阵显示实验-128*64,控制器KS0108实验准备:
18、将拨码开关S1和S2置ON运行此程序将上下左右滚动显示“姓名,马彩霞学号,3100601033班级,通信1002”出现菜单,按键选择。*/ #define LCD_DATA P2 #define LCD_RS P30 #define LCD_RW P31 #define LCD_E P32 #define LCD_CS1 P34 #define LCD_CS2 P33 #define LCD_RST P35 void Delay1ms(unsigned char); #define SELECTCS 0char code zero= /0/0x00,0xE0,0x10,0x08,0x08,0x
19、10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00, ; char code one= /1/0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00, ; char code two= /2/0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00, ; char code three= /3/0x00,0x30,0x08,0x88,0x
20、88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00, ; char code four= /4/0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00, ; char code five= /5/0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00, ; char code six= /6/0x00,0xE0,0x10,0x
21、88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00, ; char code seven= /7/0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00, ; char code eight= /8/0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00, ; char code nine= /9/0x00,0xE0
22、,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00, ; char code mao= /:/0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00, ; char code dot= /./0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00, ; char code wen= /温/0x10,0
23、x21,0x86,0x70,0x00,0x7E,0x4A,0x4A,0x4A,0x4A,0x4A,0x7E,0x00,0x00,0x00,0x00, 0x02,0xFE,0x01,0x40,0x7F,0x41,0x41,0x7F,0x41,0x41,0x7F,0x41,0x41,0x7F,0x40,0x00, ; char code du= /度/0x00,0x00,0xFC,0x04,0x24,0x24,0xFC,0xA5,0xA6,0xA4,0xFC,0x24,0x24,0x24,0x04,0x00, 0x80,0x60,0x1F,0x80,0x80,0x42,0x46,0x2A,0x12
24、,0x12,0x2A,0x26,0x42,0xC0,0x40,0x00, ; char code dian= /电/0x00,0x00,0xF8,0x48,0x48,0x48,0x48,0xFF,0x48,0x48,0x48,0x48,0xF8,0x00,0x00,0x00, 0x00,0x00,0x0F,0x04,0x04,0x04,0x04,0x3F,0x44,0x44,0x44,0x44,0x4F,0x40,0x70,0x00, ; char code ya= /压/0x00,0x00,0xFE,0x02,0x42,0x42,0x42,0x42,0xFA,0x42,0x42,0x42,0
25、x62,0x42,0x02,0x00, 0x20,0x18,0x27,0x20,0x20,0x20,0x20,0x20,0x3F,0x20,0x21,0x2E,0x24,0x20,0x20,0x00, ; char code li= /力/0x00,0x10,0x10,0x10,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x10,0x10,0xF0,0x00,0x00, 0x00,0x00,0x80,0x40,0x20,0x18,0x06,0x01,0x00,0x00,0x40,0x80,0x40,0x3F,0x00,0x00, ; char code C= /C/
26、0xC7,0x35,0x0F,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00, ; char code N= /牛顿/0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00, ; char code m= /m/0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F, ; char code V= /V/0x
27、08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00, ; charcodescreen1= 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x80,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0x80,0x80,0x00,0x80,0xC0,0x80,0x80,0x80,0x00,0x00,0x00,0xC0,0x00,0x00,0x80,0x80,0x
28、80,0xC0,0x80,0x00,0x00,0x00,0x00,0x40,0x80,0x40,0x80,0x00,0x00,0xC0,0x00,0x00,0x00,0xC0,0x40,0x40,0xC0,0x80,0x80,0x80,0xC0,0x80,0x80,0x80,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,0x00,0x00,0x00,0x00,0x
29、00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x000x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0xFC,0x80,0x40,0x04,0x04,0x040xFF,0x04,0x04,0x04,0x00,0x82,0x81,0xBE,0xEB,0xAA,0xAB,0xAA,0xEA,0xBF,0x80,0x80,0x00
30、,0x61,0x19,0xFF,0x09,0x91,0x7F,0x00,0x00,0xFF,0x00,0xC0,0x00,0x27,0x21,0x25,0x25,0x25,0xF5,0x2D,0x25,0x21,0x25,0x23,0x00,0xFF,0x20,0x23,0x3C,0x09,0x8A,0x7A,0x0A,0xFA,0x0A,0xC9,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
31、,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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x05,0xC4,0xB4,0x84,0x84,0x84,0xE5,0x9C,0x80,0x00,0x00,0x88,0x98,0xA9,0xD8
32、,0xA4,0x9C,0xA4,0x21,0x10,0x88,0x44,0x00,0x30,0xD4,0x55,0x75,0xD4,0x3C,0x54,0x54,0x75,0xD1,0x31,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
33、,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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x02,0x02,0x02,0x02,0x02,0x12,0x12
34、,0x10,0x0F,0x00,0x00,0x08,0x04,0x02,0x1F,0x02,0x14,0x10,0x09,0x09,0x04,0x02,0x00,0x00,0x1F,0x05,0x05,0x15,0x10,0x15,0x0D,0x0D,0x15,0x10,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,0x00,0x00,0x00,0x00,0x00
35、,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,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,0x00,0x00,0x00,0x00
36、,0x42,0x81,0x89,0x89,0x76,0x00,0x00,0x82,0xFF,0x80,0x00,0x00,0x7E,0x81,0x81,0x81,0x7E,0x00,0x7E,0x81,0x81,0x81,0x7E,0x00,0x7E,0x89,0x89,0x8B,0x70,0x00,0x7E,0x81,0x81,0x81,0x7E,0x00,0x00,0x82,0xFF,0x80,0x00,0x00,0x7E,0x81,0x81,0x81,0x7E,0x00,0x42,0x81,0x89,0x89,0x76,0x00,0x42,0x81,0x89,0x89,0x76,0x00
37、,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,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,0x00,0x00,0x00,0x00
38、,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x44,0xD8,0x00,0x04,0xF4,0x5C,0xF4,0x5C,0x54,0xF4,0x00,0x00,0x80,0xE0,0x1C,0x08,0xA8,0xA8,0xA8,0xAC,0xA8,0xA8,0x08,0x00,0x00,0x20,0xF0,0x00,0x00,0x00,0xE0,0x10,0x10,0x10,0xE0,0x00,0xE0,0x10,0x10,0x10,0xE0,0x00,0x60,0x10,0x10,0x90,0x60,0x00,0x00,0x00,0x00,0x00
39、,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,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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x07,0x08,0x10,0x17,0x11,0x17,0x11,0x15,0x17,0x10,0x00,0x00,0x1F,0x00,0x00,0x1E,0x0A,0x0A,0x0A,0x0A,0x1E,0x00,0x00,0x00,0x08,0x0F,0x08,0x00,0x00,0x07,0