点阵式液晶显示屏的显示程序设计单片机原理及应用课程设计.doc
【精品文档】如有侵权,请联系网站删除,仅供学习与交流点阵式液晶显示屏的显示程序设计单片机原理及应用课程设计.精品文档. 单片机原理及应用课程设计学院名称: 计算机学院 专业班级: 计算机1001 学生姓名: 秦 佳 学生学号: 3100602007 指导教师姓名: 赵念强 完成时间: 2013年7月5日 点阵式液晶显示屏的显示程序设计一、设计目的1熟练掌握C51系统仿真开发系统的应用。2加强单片机的综合运用能力、提高单片机的软件编程和调试能力,为以后的学习和开发工作打下良好基础。3掌握的液晶的工作原理以及应用设计。4掌握小系统开发设计的流程以及设计思路。二、设计方案1、实验要求:1)字符方式:从下到上滚动显示:“江苏大学计算机学院”然后交替显示:“2013年单片机课程设计”“液晶点阵显示屏程序设计”“作者姓名、班级、学号” 2)图片方式:显示相应图片(有左、右移,上下卷等多种动态方式 )3) 模拟量采样值显示(温度、压力、电位)4) 其它功能不限,可自由发挥(时钟、秒表、计算器、菜单等),拓展要求2、设计思路:将程序分成四个模块:1.主函数模块main.c2.模数转换模块ADC.c 3.液晶显示模块KS0108.c4.测试模块test7279.c其中,在main.c中定义一个功能选择菜单图片,包含课设的简介,图片的变换,模拟量的采集以及计算器的实现,该菜单功能的切换由按键功能来实现。在KS0108.c中定义了两张图片分别来简单介绍一下该课程设计,包含“江苏大学计算机学院、2013年单片机课程设计”和“秦佳、计算机1001、3100602007”;还定义了字符方式下的“液晶点阵显示屏程序设计”;定义了在ADC中要用到的0-9的数字以及计算器中要用到的各种运算符。在其中还定义了上移、下移、左移和右移函数以及计算器实现的函数。在ADC.c中定义了字符形式的“温度压力电位”以及将模拟量转换成数字量的showadc函数。各函数说明三、 程序流程图:a、 系统主流程图b、 主函数流程图初始化各部件c、 显示模块流程图d、 模数转换模块流程图开中断开始显示菜单主函数模块判断键入值并调用相应函数b液晶显示模块模数转换模块a开始判断KS0108是否空闲读取No和模拟量向LCD发送控制命令No=3No=2No=1定义各类显示函数返回压力返回电位返回温度定义初始化LCD函数结束d定义各类图像变换函数以及字符显示函数cd四、 主要的源程序及注释1、main.c#include "c8051f020.h" #include <intrins.h> void Delay1us(unsigned char us)while (us) _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); -us;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 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; / Enable 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 enabled; flags / cleared SPI0CKR = SYSCLK/2/8000000-1; / SPI clock <= 8MHz (limited by / EEPROM spec.)unsigned char Count1ms;void Timer0_Init (void) CKCON|=0x8; TMOD|=0x1; /16BitCount1ms=10; TR0 = 0; / STOP Timer0 TH0 = (-SYSCLK/1000) >> 8; / set Timer0 to overflow in 1ms TL0 = -SYSCLK/1000; TR0 = 1; / START Timer0 IE|= 0x2; void Timer0_ISR (void) interrupt 1 /1msTH0 = (-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)Delay1ms(200);Delay1ms(200);Delay1ms(200);Delay1ms(200);Delay1ms(200);T-;char GetKeyValue(void);void Show(void);void Show1(void);void showadc();void caculater();void DispBmp(char *buf);void InitLCD(void);void WaitKeyOff(void);char code screen=/功能选择0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0xC0,0xC0,0xC0,0xC0,0x40,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xC0,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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x41,0x7F,0x7F,0x40,0x00,0x00,0x30,0x70,0x60,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0xFF,0xFF,0x7F,0x7F,0x7F,0xFB,0xFF,0xFE,0x00,0x00,0x10,0x18,0xDC,0xEE,0x7F,0x1B,0xFD,0xFF,0x06,0x0C,0x0C,0x08,0x08,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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x30,0x10,0xF0,0xF0,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0xF0,0xF0,0xF0,0xF0,0x70,0xF1,0xF1,0xF0,0x00,0x00,0x00,0x00,0xF0,0xF0,0xE0,0x79,0x79,0x58,0x40,0x00,0x00,0x00,0x00,0xA0,0xA0,0xE0,0xF8,0xF8,0xF0,0xD0,0xD0,0x90,0x00,0x00,0x80,0xC0,0xF8,0xF0,0xC0,0xF0,0xF0,0xF0,0xA0,0xA0,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,0x0C,0x0E,0x0F,0x0B,0x0C,0x0C,0x00,0x06,0x0E,0x0C,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x1F,0x0F,0x0F,0x0F,0x0F,0x09,0x3F,0x3F,0x1F,0x00,0x00,0x10,0x18,0x0F,0x07,0x03,0x01,0x3F,0x3F,0x00,0x00,0x00,0x00,0x10,0x11,0x13,0x1E,0x0F,0x0F,0x1F,0x11,0x10,0x10,0x10,0x04,0x04,0x16,0x1F,0x1F,0x17,0x1F,0x0F,0x1F,0x13,0x12,0x12,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,0x04,0x26,0x32,0x3E,0xFE,0xE0,0x00,0xC0,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x88,0xE8,0xFF,0xFF,0xAC,0xBE,0xFE,0xFF,0xFF,0x7B,0x4A,0x40,0x80,0x90,0xD8,0xFF,0xFE,0xF8,0xF4,0x6C,0xEC,0xFC,0xBC,0x00,0x00,0x10,0x10,0x32,0xFE,0xFE,0xFE,0xFE,0xFE,0x1A,0x08,0x08,0x00,0x00,0x20,0xAC,0xEE,0xFE,0xFF,0xFF,0xB7,0x92,0x00,0x00,0x00,0x90,0xF1,0xFF,0xFE,0xFA,0xF6,0xFE,0xFF,0x6B,0x4A,0x40,0x40,0x60,0xF8,0xFE,0x06,0xFA,0xFC,0xFE,0xF6,0xF4,0x04,0x00,0x00,0x00,0x42,0xCE,0xFE,0xFE,0xFE,0xFE,0xFE,0x66,0x20,0x00,0x00,0x20,0xA0,0xE4,0x64,0xF4,0xF6,0xD2,0xD2,0xD0,0x90,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x81,0xC1,0xC1,0x00,0x00,0x00,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xE3,0xE2,0x03,0x83,0x81,0x83,0xC3,0xC2,0x02,0x00,0x00,0xC3,0xC3,0xC3,0xE1,0xE3,0xE3,0x21,0x00,0x01,0x01,0x00,0x80,0x82,0x82,0x82,0x83,0x03,0xE3,0xE3,0x03,0x02,0x00,0x00,0x03,0x83,0xC1,0xC0,0xE7,0xE7,0xC0,0x81,0x81,0x01,0x01,0x01,0x01,0x07,0x07,0x03,0x00,0x00,0x07,0x07,0x00,0x00,0x00,0x00,0x00,0x07,0x07,0x06,0x07,0x03,0x03,0x03,0x03,0x02,0x02,0x00,0x02,0x02,0x03,0x03,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x01,0x01,0x02,0x07,0x07,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x0E,0x0B,0x3F,0x3F,0x08,0x08,0x18,0x38,0x30,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x12,0x5A,0x7F,0x7F,0x1D,0x3E,0x3F,0x37,0x3C,0x1C,0x04,0x40,0x70,0x3F,0xCF,0xFF,0x7F,0x7F,0x3F,0x7D,0x4C,0x44,0x40,0x08,0x08,0x4C,0x4F,0x67,0x36,0x1E,0x6F,0x79,0x7F,0x0F,0x00,0x00,0xC3,0xFF,0xFD,0xFD,0xFD,0x7F,0x7F,0x4E,0x66,0x72,0x20,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,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,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,;void Choose() char i; InitLCD();DispBmp(screen); for(;) do i=GetKeyValue(); while(i=-1); WaitKeyOff(); if(i=0x01) Show(); else if(i=0x02) Show1(); if(i=0x03) showadc(); else if(i=0x04) caculater(); break;void TestLCD(void);void init_adc(void); void main (void) WDTCN = 0xde;WDTCN = 0xad; /关看门狗SYSCLK_Init (); /初始化时钟Timer0_Init();/初始化定时器PORT_Init (); /初始化IO口SPI0_Init (); /初始化SPI0 init_adc(); /初始化adc CPT1CN|=0x80;/使能比较器1REF0CN = 0x03; /使能片内参考电压DAC0CN |= 0x80;/使能DAC0DAC0H=0;DAC0L=0;EA=1;/开中断 for(;) Choose();2、ADC.c#include "c8051F020.h"#include <intrins.h>#define MUX_TEMP0x08#define MUX_VOLT0x01#define MUX_PRESS0x02unsigned int idata Temp, Press, Volt;unsigned char idata mux_select;sfr16 ADC0 = 0xbe; / ADC0 data/*- 文字: 温度压力电位 -*/char code wen=0x10,0x21,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,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,0x12,0x2A,0x26,0x42,0xC0,0x40,0x00,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,0x00,0xC0,0x30,0xEC,0x03,0x2A,0xC8,0x09,0x0A,0x0E,0x08,0xE8,0x48,0x08,0x00,0x00,0x01,0x00,0x00,0x7F,0x20,0x20,0x20,0x27,0x20,0x30,0x2E,0x21,0x20,0x20,0x20,0x00,0x00,0x00,0xFE,0x02,0x42,0x42,0x42,0x42,0xFA,0x42,0x42,0x42,0x62,0x42,0x02,0x00,0x20,0x18,0x27,0x20,0x20,0x20,0x20,0x20,0x3F,0x20,0x21,0x2E,0x24,0x20,0x20,0x00,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,;void init_adc(void)ADC0CN = 0x81; / ADC0 enabled; normal tracking / mode; ADC0 conversions are initiated / on write to AD0BUSY; ADC0 data is / left-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; / disable ADC0 window compare interruptvoid 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)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;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_select = 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 (Press<10) Press=0; /压力return Press;void shownum(char x,char y,char num); char GetKeyValue(void);void LCD_WriteHZ(char x,char y,char *Dot);void InitLCD(void);void Delay1ms(unsigned char T);void WaitKeyOff(void);void showadc()unsigned int w; char i,a,flag; char buf4;flag=0; for(;) do if(flag) w = GetADCValue(flag); Delay1ms(250); buf0=(w%10000)/1000; buf1=(w%1000)/100; buf2=(w%100)/10; buf3=(w%10); for(a=0;a<4;a+) shownum(48+16*a,2,bufa); i=GetKeyValue(); while(i=-1); WaitKeyOff(); InitLCD(); switch(i) case 4: LCD_WriteHZ(10,2,wen);LCD_WriteHZ(28,2,wen+32);flag=1;break; case 5: LCD_WriteHZ(10,2,wen+32*2);LCD_WriteHZ(28,2,wen+32*3);flag=2;break; case 6: LCD_WriteHZ(10,2,wen+32*4);LCD_WriteHZ(28,2,wen+32*5);flag=3;break; default:return;3、KS0108.c#include "c8051F020.h"#include <intrins.h>#define LCD_DATA P2#define LCD_RS P30#define LCD_RW P31#define LCD_E P32#define LCD_CS1 P33#define LCD_CS2 P34#define LCD_RST P35void Delay1ms(unsigned char);/*- 宽度x高度=128x64 -*/char code screen1=/江苏大学计算机学院、2013年单片机课程设计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,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