S3F9488LCD驱动IAR C编程示例//********************************//
#include "ioS3C9488.h"// #include "intrinsics.h"//包含内部函数 #include "math.h" //******************************************************** //************************************************ //**此处为宏定义替换****** #define uchar unsigned char #define uint unsigned int #define nop (__no_operation()) //将后者指令行缩写为nop; #define di (__disable_interrupt()) //将后者指令行缩写为di; #define ei (__enable_interrupt()) //将后者指令行缩写为ei; #define Set_Bit(byte,bit) (byte|=(1<#define Clr_Bit(byte,bit) (byte&=~(1<#define Com_Bit(byte,bit) (byte^=(1<#define Test_Bit(byte,bit) (byte&(1<//****************************************************************** uchar second,min,hour; uchar msd,lsd; uchar beepc,keynum,keyram; uchar settime,setnum,_500ms,_100ms1; uchar keepc; uchar flaga,flagb; //****************************************** //beep_f bit flaga,0 //key_f bit flaga,1 //col_f bit flaga,2 //add_f bit flaga,3 //dec_f bit flaga,4 //_05s_f bit flaga,5 //keep_f bit flaga,6 /dd_f bit flagb,0; //kdec_f bit flagb,1 //********************************************************************** __code const volatile uchar SmartOption[4] @0x003c = {0xff,0xaa,0x50,0x03}; __no_init __tinyp1 volatile uchar LCDRAM[11] @0x00; __code const volatile uchar segtable1[]={//0000*egf 0x05, //0 0x00, //1 0x06, //2 0x02, //3 0x03, //4 0x03, //5 0x07, //6 0x00, //7 0x07, //8 0x03, //9 0x00 //10 }; __code const volatile uchar segtable2[]={//0000dcba 0x0f, //0 0x06, //1 0x0b, //2 0x0f, //3 0x06, //4 0x0d, //5 0x0d, //6 0x07, //7 0x0f, //8 0x0f, //9 0x00 //10 }; //************************************************************************* //***程序所用函数声明***** //***凡程序中所用到的函数请先在这里声明*** __interrupt void int_9488(); //中断函数 void display(void); void binbcd(uchar x); void beeponoff(void); void keycheck(void); void dokey(uchar x); void setclock(void); uchar readkey(); //******************************************************************* //函数:void main(void) //功能:主程序 //******************************************************************* void main(void) { uchar buffer = SmartOption[0]; CLKCON=0x18;OSCCON=0x00;LCDCON=0x9f;LCDVOL=0x8f; P0CONL=0x0a;P0CONH=0xaa;P0PUR=0x00; P1CONL=0x20;P1CONH=0xff;P1PUR=0x00; P4CONL=0xbf;P4CONH=0x2a; P2CONL=0xff;P2CONH=0xff; P3CONL=0x4a;P3CONH=0xaa;P3INT=0x00;P3PND=0x00; Set_Bit(P1,2); STPCON=0xa5;VLDCON=0x2c;WDTCON=0xaa;WTCON=0xf2; BTCON=0x0b;TACON=0X8b;TADATA=128;TBCON=0x00;TBDATAH=0x00;TBDATAL=0x00;ADCON=0x00; beepc=0x10; ei; for(;;) {if(Test_Bit(P1,3)) {nop;nop;nop;nop;nop;nop; CLKCON=0x18;OSCCON=0x00;LCDCON=0x9f;LCDVOL=0x8f; P0CONL=0x0a;P0CONH=0xaa;P0PUR=0x00; P1CONL=0x20;P1CONH=0xff;P1PUR=0x00; P4CONL=0xbf;P4CONH=0x2a; P2CONL=0xff;P2CONH=0xff; P3CONL=0x4a;P3CONH=0xaa;P3INT=0x00;P3PND=0x00; Set_Bit(P1,2); STPCON=0xa5;VLDCON=0x2c;WDTCON=0xaa;ADCON=0x00; BTCON=0x0b;if(!Test_Bit(TACON,1)) Set_Bit(TACON,1); setclock(); display(); keycheck(); beeponoff(); } else {CLKCON=0x18;OSCCON=0x00;LCDCON=0x00; LCDVOL=0x00; P0CONH=0xaa;P0CONL=0xaa;P0PUR=0x00; P0=0x00; P1CONH=0xaa;P1CONL=0x2a;P1PUR=0x00; P1=0x00; P2CONH=0xaa;P2CONL=0x6A; P2=0x00; P3CONH=0xaa;P3CONL=0x4a;P3PND=0x00; P3=0x00; P4CONH=0x2a;P4CONL=0xaa; P4=0x00; STPCON=0xa5;VLDCON=0x2c;WDTCON=0xaa; BTCON=0x0b;TACON=0X89;ADCON=0x00; asm("stop"); } } } //****************************************************************** //函数:void setclock(void) //****************************************************************** void setclock(void) {if(setnum==1){if(Test_Bit(flaga,3)||Test_Bit(flagb,0)){Clr_Bit(flagb,0);Clr_Bit(flaga,3);hour++;if(hour>=24) hour=0;} if(Test_Bit(flaga,4)||Test_Bit(flagb,1)){Clr_Bit(flagb,1);Clr_Bit(flaga,4);hour--;if(hour==0xff) hour=23;} } if(setnum==2){if(Test_Bit(flaga,3)){Clr_Bit(flaga,3);min++; if(min>=60) min=0;} if(Test_Bit(flaga,4)){Clr_Bit(flaga,4);min--;if(min==0xff) min=59;} } } //************************************************* //函数:void display(uchar *s) //************************************************* void display(void) {uchar x,y; if(Test_Bit(flaga,5)) {Clr_Bit(flaga,5); y=0x00;y|=0x00; LCDRAM[0]=y; LCDRAM[1]=0x00; y=0x00;y|=0x00; LCDRAM[2]=y; //********************************************* binbcd(min); x=lsd;if(setnum==2){if(!Test_Bit(flaga,2)) x=10;} LCDRAM[3]=segtable2[x]; x=lsd;if(setnum==2){if(!Test_Bit(flaga,2)) x=10;} LCDRAM[4]=segtable1[x]; x=msd;if(setnum==2){if(!Test_Bit(flaga,2)) x=10;} LCDRAM[5]=segtable2[x]; x=msd;if(setnum==2){if(!Test_Bit(flaga,2)) x=10;} y=segtable1[x];y|=0x08; LCDRAM[6]=y; //********************************************* binbcd(hour); x=lsd;if(setnum==1){if(!Test_Bit(flaga,2)) x=10;} y=segtable2[x]; LCDRAM[7]=y; x=lsd;if(setnum==1){if(!Test_Bit(flaga,2)) x=10;} y=segtable1[x]; LCDRAM[8]=y; x=msd;if(setnum==1){if(!Test_Bit(flaga,2)) x=10;} LCDRAM[9]=segtable2[x]; x=msd;if(setnum==1){if(!Test_Bit(flaga,2)) x=10;} LCDRAM[10]=segtable1[x]; } } //********************************************** //函数:void binbcd(uchar x) //********************************************** void binbcd(uchar x) {msd=x/10;x=x%10;lsd=x; } //**************************************************************** //函数:void keycheck(void) //**************************************************************** void keycheck(void) {uchar keyreg=0; if(Test_Bit(flaga,1)) {Clr_Bit(flaga,1); switch(keynum) {case 0: keyreg=readkey();if(keyreg!=0) {keynum++;keyram=keyreg;} break; case 1: keyreg=readkey(); if(keyreg==keyram) keynum++; else {...} } |
ic168@zh-ic.COM
开发工具:B6078S@163.com
网站相关建议:zh-ic@163.com
|
|||||||||