//******************************** //產(chǎn)品名稱: IAR-C編程示例 //使用MCU: S3F9454 //FOSC = 3.2MHZ //以下示例中很多變量及定義可能并未 //用到,在此僅僅作為示范性列示 //******************************** #include "ioS3C9454.h"http:// #include "intrinsics.h"http://包含內(nèi)部函數(shù) //************************************************ //**此處為宏定義替換****** #define uchar unsigned char #define uint unsigned int #define nop (__no_operation()) //將后者指令行縮寫為nop; #define di (__disable_interrupt()) //將后者指令行縮寫為di; #define ei (__enable_interrupt()) //將后者指令行縮寫為ei; //************************************************ //**此處定義程序所用到的全局變量******* uchar RUNFLAG = 0; uchar DISPFLAG = 0; uchar ERRFLAG = 0; //錯誤代碼標志寄存器 uchar KEY_CODE = 0; //鍵掃描碼 //************************************************************************* //***程序所用函數(shù)聲明***** //***凡程序中所用到的函數(shù)請先在這里聲明*** __interrupt void int_9454(); void chip_init(); void LedScan(); //************************************************************************* //************************************************************************* //**定義9454的SMART OPTION值**** //**003CH,must be initialized to 0 //**003DH,must be initialized to 0 //**003EH,enable LVR(2.3V) //**003FH,internal RC(3.2MHZ in Vdd=5V) //************************************* __code const volatile uchar SmartOption[4] @0x003c = {0x0,0x0,0xe7,0x03}; //************************************************************************* //************************************************************************* //數(shù)碼管顯示代碼定義(在ROM=0X40) __code const volatile uchar DigitCode[12] @0x0040 = { 0x03, //'0' 0x9f, //'1' 0x25, //'2' 0x0d, //'3' 0x99, //'4' 0x49, //'5' 0x41, //'6' 0x1f, //'7' 0x01, //'8' 0x09, //'9' 0xff, //'A' 0x61, //'E' }; //************************************************************************** //========================主程序控制=========================== void main(void) { uint loop; //***填充系統(tǒng)SMART OPTION***/ uchar buffer = SmartOption[0]; //***芯片啟動初始化過程***// chip_init(); //***主循環(huán)開始***// while(1) { P2 = 0x00; //以下定時取反P2口輸出狀態(tài)// for(loop=0;loop<50;loop++); P2 = 0xff; for(loop=0;loop<50;loop++); } } //****************************************************************** //****啟動時IO初始化子過程****** void chip_init() { BTCON = 0xa3; //Watch-dog disable CLKCON = 0x18; //selet non-divided CPU clock P0PND = 0x0; //P0/INT disable P0CONH = 0xdf; //P0.7 is as A/D convert port //P0.6 is PWM output //P0.5 is as A/D convert port //P0.4 is as A/D convert port P0CONL = 0xfa; //P0.3 is as A/D convert port //P0.2 is as A/D convert port //P0.0,P0.1 is as push-pull output port P0 = 0x0; P1CON = 0xa; //P1.0 is as push-pull output port //P1.1 is as push-pull output port P1 = 0x0; P2CONH = 0x2a; //P2.0-P2.5 is as push-pull output P2CONL = 0xaa; //P2.6 is as A/D input P2 = 0x1e; PWMDATA = 0x0; PWMCON = 0x5c; //PWM input clock is fosc/8,enable PWM output //reload from 6 bit coun T0DATA = 0x32; T0CON =0x4a; //TMR0 start count,f=fosc/256 //enable TMR0 interrupt/4ms P2 = 0xff; } //************************************************************************* //**中斷向量及服務程序定義******** #pragma vector=0x00 __interrupt void int_9454() { T0CON = T0CON & 0xfe; //必須清T0中斷標志 LedScan(); //數(shù)碼管顯示掃描過程 } //************************************************************************* void LedScan(void) { //這里是LED顯示定時掃描過程 }
|