键盘调节参数LCD5110同步显示.doc_第1页
键盘调节参数LCD5110同步显示.doc_第2页
键盘调节参数LCD5110同步显示.doc_第3页
键盘调节参数LCD5110同步显示.doc_第4页
键盘调节参数LCD5110同步显示.doc_第5页
已阅读5页,还剩32页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

#include /* common defines and macros */#include #pragma LINK_INFO DERIVATIVE mc9s12xs128#define LCD_SCEPORTB_PB3#define LCD_RST PORTB_PB4#define LCD_DCPORTB_PB2#define LCD_SDINPORTB_PB1#define LCD_SCLKPORTB_PB0#define keyO1 PORTA_PA1 /#define keyO2 PORTA_PA2 /#define keyO3 PORTA_PA3 /#define keyI1 PORTA_PA4 /#define keyI2 PORTA_PA5 /#define keyI3 PORTA_PA6 /#define keyI4 PORTA_PA7 /#define com 0#define data1unsigned char keyout;unsigned char keycon;unsigned char keybit;unsigned char keybuf;unsigned char i=0;unsigned char temp;unsigned long int result;unsigned char enc03=103 ;unsigned char mma7260=88;unsigned char speed=50 ;unsigned char speed_p=100 ;unsigned char speed_i=200 ;unsigned char angle_p=50 ;unsigned char angle_d=100;unsigned char direction_p=100;unsigned char direction_d=50; unsigned char ge,shi,bai;float AD_result8;/存放AD转换结果unsigned char lingpian;const char shuzi=0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E,/ 00x00, 0x00, 0x42, 0x7F, 0x40, 0x00,/ 10x00, 0x42, 0x61, 0x51, 0x49, 0x46,/ 20x00, 0x21, 0x41, 0x45, 0x4B, 0x31,/ 30x00, 0x18, 0x14, 0x12, 0x7F, 0x10,/ 40x00, 0x27, 0x45, 0x45, 0x45, 0x39,/ 50x00, 0x3C, 0x4A, 0x49, 0x49, 0x30,/ 60x00, 0x01, 0x71, 0x09, 0x05, 0x03,/ 70x00, 0x36, 0x49, 0x49, 0x49, 0x36,/ 80x00, 0x06, 0x49, 0x49, 0x29, 0x1E,/ 90x00, 0x14, 0x08, 0x3E, 0x08, 0x14,/ * 10;const char zimu= 0x00, 0x20, 0x54, 0x54, 0x54, 0x78,/ a 0 0x00, 0x7F, 0x48, 0x44, 0x44, 0x38,/ b 1 0x00, 0x38, 0x44, 0x44, 0x44, 0x20,/ c 2 0x00, 0x38, 0x44, 0x44, 0x48, 0x7F,/ d 3 0x00, 0x38, 0x54, 0x54, 0x54, 0x18,/ e 4 0x00, 0x08, 0x7E, 0x09, 0x01, 0x02,/ f 5 0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C,/ g 6 0x00, 0x7F, 0x08, 0x04, 0x04, 0x78,/ h 7 0x00, 0x00, 0x44, 0x7D, 0x40, 0x00,/ i 8 0x00, 0x40, 0x80, 0x84, 0x7D, 0x00,/ j 9 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00,/ k 10 0x00, 0x00, 0x41, 0x7F, 0x40, 0x00,/ l 11 0x00, 0x7C, 0x04, 0x18, 0x04, 0x78,/ m 12 0x00, 0x7C, 0x08, 0x04, 0x04, 0x78,/ n 13 0x00, 0x38, 0x44, 0x44, 0x44, 0x38,/ o 14 0x00, 0xFC, 0x24, 0x24, 0x24, 0x18,/ p 15 0x00, 0x18, 0x24, 0x24, 0x18, 0xFC,/ q 16 0x00, 0x7C, 0x08, 0x04, 0x04, 0x08,/ r 17 0x00, 0x48, 0x54, 0x54, 0x54, 0x20,/ s 18 0x00, 0x04, 0x3F, 0x44, 0x40, 0x20,/ t 19 0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C,/ u 20 0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C,/ v 21 0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C,/ w 22 0x00, 0x44, 0x28, 0x10, 0x28, 0x44,/ x 23 0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C,/ y 24 0x00, 0x44, 0x64, 0x54, 0x4C, 0x44,/ z 25 0x00, 0x40, 0x40, 0x40, 0x40, 0x40,/ _ 26 ;/总线时钟/void SetBusCLK_64M(void) CLKSEL=0X00; /disengage PLL to system PLLCTL_PLLON=1; /turn on PLL SYNR =0xc0 | 0x07; REFDV=0x80 | 0x01; POSTDIV=0x00; /pllclock=2*osc*(1+SYNR)/(1+REFDV)=128MHz; _asm(nop); /BUS CLOCK=64M _asm(nop); while(!(CRGFLG_LOCK=1); /when pll is steady ,then use it; CLKSEL_PLLSEL =1; /engage PLL to system; /五路AD初始化/void AD_init(void) / ATD0CTL0=0; /AD转换起始通道为AN0 ATD0CTL1=0x00; /允许指定AD口做外部触发输入口8位结果,采样前采样电容不放电 1 ATD0CTL2=0x40; /启动AD 标志寄存器快速清零 ATD0CTL3=0xc0; /结果右对齐,非FIFO模式,冻结模式继续转换 转换长度8 ATD0CTL4=0x03; /0000 0011 -采样时间为 4 个 AD 时钟周期 ,PRS=1,ATDClock=BUSClock/(2*(PRS+1)=8MHz ATD0CTL5=0x30; /通道0 连续转换起始通道为AN0 ATD0DIEN=0x00; /禁用数字输入缓冲 /读取AD值/void get_ad(void) AD_result0=ATD0DR0L; AD_result1=ATD0DR1L; AD_result2=ATD0DR2L; AD_result3=ATD0DR3L; AD_result4=ATD0DR4L; AD_result5=ATD0DR5L; AD_result6=ATD0DR6L; AD_result7=ATD0DR7L;/一个简单的延时函数/void delay(unsigned int ms) unsigned int i,j; for(j=0;jms;j+) for(i=0;i110;i+); /向液晶写命令和数据/void send_comordata(unsigned char Data,unsigned char Com)unsigned char a;LCD_SCE=0;LCD_DC=Com;for(a=0;a8;a+)if(Data&0x80)LCD_SDIN=1;elseLCD_SDIN=0;LCD_SCLK=0;LCD_SCLK=1;Data=Data1;LCD_SCE=1;/设置显示地址/void LCD_POS(unsigned char X,unsigned char Y)send_comordata(0x40|Y,com);send_comordata(0x80|X,com);/液晶清屏函数/void LCD_clear(void)unsigned char t;unsigned char k;LCD_POS(0,0);for(t=0;t6;t+) for(k=0;k84;k+) send_comordata(0x00,data); /向液晶写入汉字/*void display_hanzi(unsigned char A,unsigned char X,unsigned char Y)unsigned char line;LCD_POS(X*12,Y);for(line=0;line12;line+)send_comordata(hanziAline,data);LCD_POS(X*12,Y+1);for(line=12;line24;line+)send_comordata(hanziAline,data); */向液晶写入字母等其他字符/void display_zimu(unsigned char A,unsigned char X,unsigned char Y)unsigned char line;LCD_POS(X*6,Y);for(line=0;line6;line+)send_comordata(zimuA*6+line,data);/向液晶写入数字/void diaplay_shuzi(unsigned char A,unsigned char X,unsigned char Y)unsigned char line;LCD_POS(X*6,Y);for(line=0;line5)keycon=0;keybit=1;/diaplay_shuzi(0,1,1);else if(keybuf=1)if(keybit=1)keybit=0;keyout=10;/ display_hanzi(0,1,1);else if(keybuf=2)if(keybit=1)keybit=0;keyout=7;/diaplay_shuzi(7,1,1);else if(keybuf=3)if(keybit=1)keybit=0;keyout=4;/diaplay_shuzi(4,1,1);else if(keybuf=4)if(keybit=1)keybit=0;keyout=1;/diaplay_shuzi(1,1,1);else if(keybuf=5)if(keybit=1)keybit=0;keyout=0;/diaplay_shuzi(0,1,1);else if(keybuf=6)if(keybit=1)keybit=0;keyout=8;/diaplay_shuzi(8,1,1);else if(keybuf=7)if(keybit=1)keybit=0;keyout=5;/diaplay_shuzi(5,1,1);else if(keybuf=8)if(keybit=1)keybit=0;keyout=2;/diaplay_shuzi(2,1,1);else if(keybuf=9)if(keybit=1)keybit=0;keyout=11;/ display_hanzi(1,1,1);else if(keybuf=10)if(keybit=1)keybit=0;keyout=9;/ diaplay_shuzi(9,1,1);else if(keybuf=11)if(keybit=1)keybit=0;keyout=6;/diaplay_shuzi(6,1,1);else if(keybuf=12)if(keybit=1)keybit=0;keyout=3;/diaplay_shuzi(3,1,1);elsekeybit=0;void keyswait() temp=PORTA; temp=temp&0xf0; while(temp!=0xf0) temp=PORTA; temp=temp&0xf0; /void shuzifenjie(unsigned char number) bai=number/100; shi=number%100/10; ge=number%10; /void printinit(void)/enc03/ display_zimu(4,0,0); display_zimu(13,1,0); display_zimu(2,2,0); shuzifenjie(enc03); diaplay_shuzi(bai,5,0); diaplay_shuzi(shi,6,0); diaplay_shuzi(ge,7,0);/mma7260/ display_zimu(12,0,1); display_zimu(12,1,1); display_zimu(0,2,1); shuzifenjie(mma7260); diaplay_shuzi(bai,5,1); diaplay_shuzi(shi,6,1); diaplay_shuzi(ge,7,1);/speed速度/ display_zimu(18,0,2); display_zimu(15,1,2); display_zimu(4,2,2); shuzifenjie(speed); diaplay_shuzi(bai,5,2); diaplay_shuzi(shi,6,2); diaplay_shuzi(ge,7,2);/速度参数P和I/ display_zimu(18,0,3); display_zimu(26,1,3); display_zimu(15,2,3); shuzifenjie(speed_p); diaplay_shuzi(bai,5,3); diaplay_shuzi(shi,6,3); diaplay_shuzi(ge,7,3); display_zimu(8,9,3); shuzifenjie(speed_i); diaplay_shuzi(bai,11,3); diaplay_shuzi(shi,12,3); diaplay_shuzi(ge,13,3);/直立P和D/ display_zimu(0,0,4); display_zimu(26,1,4); display_zimu(15,2,4); shuzifenjie(angle_p); diaplay_shuzi(bai,5,4); diaplay_shuzi(shi,6,4); diaplay_shuzi(ge,7,4); display_zimu(3,9,4); shuzifenjie(angle_d); diaplay_shuzi(bai,11,4); diaplay_shuzi(shi,12,4); diaplay_shuzi(ge,13,4);/方向P和D/ display_zimu(3,0,5); display_zimu(26,1,5); display_zimu(15,2,5); shuzifenjie(direction_p); diaplay_shuzi(bai,5,5); diaplay_shuzi(shi,6,5); diaplay_shuzi(ge,7,5); display_zimu(3,9,5); shuzifenjie(direction_d); diaplay_shuzi(bai,11,5); diaplay_shuzi(shi,12,5); diaplay_shuzi(ge,13,5); void canshuxiugai(void) unsigned int counter=1; unsigned char flag=1; /* while(flag) keypro(); keyswait(); if(keyout=1) LCD_POS(4*6,0); for(i=0;i6;i+) send_comordata(0x00,data); LCD_POS(4*6,1); for(i=0;i6;i+) send_comordata(0x00,data); LCD_POS(4*6,2); for(i=0;i6;i+) send_comordata(0x00,data); LCD_POS(4*6,3); for(i=0;i6;i+) send_comordata(0x00,data); LCD_POS(4*6,4); for(i=0;i6;i+) send_comordata(0x00,data); LCD_POS(4*6,5); for(i=0;i6;i+) send_comordata(0x00,data); LCD_POS(10*6,3); for(i=0;i6;i+) send_comordata(0x00,data); LCD_POS(10*6,4); for(i=0;i6;i+) send_comordata(0x00,data); LCD_POS(10*6,5); for(i=0;i6;i+) send_comordata(0x00,data); flag=0; */ while(flag) if(counter=1) while(counter=1) & (flag=1) diaplay_shuzi(10,4,0); /* LCD_POS(4*6,1); for(i=0;i6;i+) send_comordata(0x00,data); LCD_POS(4*6,2); for(i=0;i6;i+) send_comordata(0x00,data); LCD_POS(4*6,3); for(i=0;i6;i+) send_comordata(0x00,data); LCD_POS(4*6,4); for(i=0;i6;i+) send_comordata(0x00,data); LCD_POS(4*6,5); for(i=0;i6;i+) send_comordata(0x00,data); LCD_POS(10*6,3); for(i=0;i6;i+) send_comordata(0x00,data); LCD_POS(10*6,4); for(i=0;i6;i+) send_comordata(0x00,data);*/ LCD_POS(10*6,5); for(i=0;i6;i+) send_comordata(0x00,data); keypro(); if(keyout=2) enc03+; if(keyout=5) enc03-; shuzifenjie(enc03); diaplay_shuzi(bai,5,0); diaplay_shuzi(shi,6,0); diaplay_shuzi(ge,7,0); get_ad(); delay(2000); enc03=(unsigned char)(AD_result5*0.117+90); shuzifenjie(enc03); diaplay_shuzi(bai,5,0); diaplay_shuzi(shi,6,0); diaplay_shuzi(ge,7,0);/ get_ad(); delay(2000); lingpian=ATD0DR1L; shuzifenjie(lingpian); diaplay_shuzi(bai,11,0); diaplay_shuzi(shi,12,0); diaplay_shuzi(ge,13,0); lingpian=ATD0DR3L; shuzifenjie(lingpian); diaplay_shuzi(bai,11,1); diaplay_shuzi(shi,12,1); diaplay_shuzi(ge,13,1);/ keypro(); if(keyout=4) keyswait(); counter+; if(keyout=1) LCD_POS(4*6,0); for(i=0;i6;i+) send_comordata(0x00,data); /* LCD_POS(4*6,0); for(i=0;i6;i+) send_comordata(0x00,data); LCD_POS(4*6,1); for(i=0;i6;i+) send_comordata(0x00,data); LCD_POS(4*6,2); for(i=0;i6;i+) send_comordata(0x00,data); LCD_POS(4*6,3); for(i=0;i6;i+) send_comordata(0x00,data); LCD_POS(4*6,4); for(i=0;i6;i+) send_comordata(0x00,data); LCD_POS(4*6,5); for(i=0;i6;i+) send_comordata(0x00,data); LCD_POS(10*6,3); for(i=0;i6;i+) send_comordata(0x00,data); LCD_POS(10*6,4); for(i=0;i6;i+) send_comordata(0x00,data); LCD_POS(10*6,5); for(i=0;i6;i+) send_comordata(0x00,data); */ flag=0; if(counter=2) while(counter=2) & (flag=1) diaplay_shuzi(10,4,1); LCD_POS(4*6,0); for(i=0;i6;i+) send_comordata(0x00,data);/* LCD_POS(4*6,2); for(i=0;i6;i+) send_comordata(0x00,data); LCD_POS(4*6,3); for(i=0;i6;i+) send_comordata(0x00,data); LCD_POS(4*6,4); for(i=0;i6;i+) send_comordata(0x00,data); LCD_POS(4*6,5); for(i=0;i6;i+) send_comordata(0x00,data); LCD_POS(10*6,3); for(i=0;i6;i+) send_comordata(0x00,data); LCD_POS(10*6,4); for(i=0;i6;i+) send_comordata(0x00,data); LCD_POS(10*6,5); for(i=0;i6;i+) send_comordata(0x00,data); */ keypro(); if(keyout=2) mma7260+; if(keyout=5) mma7260-; shuzifenjie(mma7260); diaplay_shuzi(bai,5,1); diaplay_shuzi(shi,6,1); diaplay_shuzi(ge,7,1); get_ad(); delay(2000); mma7260=(unsigned char)(AD_result7*0.157+60); shuzifenjie(mma7260); diaplay_shuzi(bai,5,1);

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论