资源描述:
《利用lcd演示q格式运算》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、利用LCD演示Q格式运算/*Main.c*/#include"global.c"voidSystemInit();voidKickDog();voidShowChar(unsignedchar,unsignedchar,unsignedchar);voidInit_Lcd(void);voidClr_Lcd(void);voidJudge1_Ready(void);voidJudge2_Ready(void);voidWrite_Code(void);voidWrite1_Data(void);voidWrite2_Data(void);voidLcd_Delay(void);voidL
2、cd_Delay1(void);voidQCACU();unsignedinttemp1,temp2;unsignedlongcode_addr,data_addr;unsignedintLineChar=16;unsignedintColumnChar=8;unsignedintchresult[2][16]={{0x00,0x11,0x0e,0x15,0x0a,0x11,0x0e,0x15,0x1d,0x12,0x0e,0x12,0x15,0x00,0x00,0x00},/*;21H!*/{00,00,00,0x0,0x0,00,00,00,00,00,00,00,00,00,00,
3、00}};intqfloat;main(){SystemInit();//系统初始化QCACU();MCRA=MCRA&0xC0FF;//IOPB0-6设为IO口模式PBDATDIR=0xFFC2;//所有LED=0PBDATDIR=PBDATDIR
4、0x003D;//所有LED=1code_addr=0x8010;data_addr=0x8000;MCRC=MCRC&0xFFF0;PEDATDIR=PEDATDIR
5、0x0200;PEDATDIR=PEDATDIR&0xFFFD;asm("nop");asm("nop");asm("nop");asm("nop");PEDATDIR=P
6、EDATDIR
7、0x0202;Init_Lcd();ShowChar(3,0,0);while(1);}voidQCACU(){unsignedinti=0,m=0,n=0,ch,qf2;intendflag=1;unsignedlongintqf=0x180;/*Q8格式表示为1.5*/unsignedint*addr=(unsignedint*)0x8500;/*数据存储地址*/qf=(qf*qf)>>8;qfloat=(int)qf;/*Q8格式qfloat=576*/*addr=qfloat;}voidSystemInit(){asm("SETCINTM");/*关闭总中断*/a
8、sm("CLRCSXM");/*禁止符号位扩展*/asm("CLRCCNF");/*B0块映射为on-chipDARAM*/asm("CLRCOVM");/*累加器结果正常溢出*/SCSR1=0x83FE;/*系统时钟CLKOUT=20*0.5=10M*//*打开ADC,EVA,EVB,CAN和SCI的时钟,系统时钟CLKOUT=10M*/WDCR=0x006F;/*禁止看门狗,看门狗时钟64分频*/KickDog();/*初始化看门狗*/IFR=0xFFFF;/*清除中断标志*/IMR=0x0000;/*关闭中断*/}voidShowChar(unsignedcharlin,unsig
9、nedcharcolumn,unsignedchark){unsignedchari;unsignedintStartAddr;StartAddr=lin*LineChar+column;//定位起始行for(i=0;i<16;i++){data1=(unsignedchar)(StartAddr);data2=(unsignedchar)(StartAddr>>8);data3=0x24;Write1_Data();Write2_Data();Write_Code();data1=chresult[k][i];Write1_Data();data3=0xc4;Write_Code();
10、StartAddr=StartAddr+1;}}voidInit_Lcd(){data1=0x00;//图形区首址(0000H)data2=0x08;data3=0x42;Write1_Data();Write2_Data();Write_Code();data1=0x10;//图形区宽度data2=0x00;data3=0x43;Write1_Data();Write2_Data();Write_Code();data1=0x00