程序在12864液晶上顯示一首詞,按鍵可翻動詞句。
0.png (6.42 KB, 下載次數: 79)
下載附件
2017-10-25 00:29 上傳
單片機源程序如下:
- /*---------------------------------------------------------*/
- /************************************************************
- 飛翔科技MC9S12XS128汽車電子開發(fā)板
- ************************************************************/
- /*---------------------------------------------------------*/
- #include <hidef.h> /* common defines and macros */
- #include "derivative.h" /* derivative-specific definitions */
- #include "LCD.h"
- #define LEDCPU PORTK_PK4
- #define LEDCPU_dir DDRK_DDRK4
- #define KEY1 PTIH_PTIH3
- #define KEY2 PTIH_PTIH2
- #define KEY1_dir DDRH_DDRH3
- #define KEY2_dir DDRH_DDRH2
- #define BUS_CLOCK 32000000 //總線頻率
- #define OSC_CLOCK 16000000 //晶振頻率
- char *poem[11] = {
- "長征",
- "毛澤東",
- "紅軍不怕遠征難,",
- "萬水千山只等閑,",
- "五嶺逶迤騰細浪,",
- "烏蒙磅礴走泥丸。",
- "金沙水拍云崖暖,",
- "大渡橋橫鐵索寒,",
- "更喜岷山千里雪,",
- "三軍過后盡開顏!",
- "",
- } ;
- unsigned char single = 0; //液晶翻頁的標志符
- /*************************************************************/
- /* 初始化鎖相環(huán) */
- /*************************************************************/
- void INIT_PLL(void)
- {
- CLKSEL &= 0x7f; //set OSCCLK as sysclk
- PLLCTL &= 0x8F; //Disable PLL circuit
- CRGINT &= 0xDF;
-
- #if(BUS_CLOCK == 40000000)
- SYNR = 0x44;
- #elif(BUS_CLOCK == 32000000)
- SYNR = 0x43;
- #elif(BUS_CLOCK == 24000000)
- SYNR = 0x42;
- #endif
- REFDV = 0x81; //PLLCLK=2×OSCCLK×(SYNDIV+1)/(REFDIV+1)=64MHz ,fbus=32M
- PLLCTL =PLLCTL|0x70; //Enable PLL circuit
- asm NOP;
- asm NOP;
- while(!(CRGFLG&0x08)); //PLLCLK is Locked already
- CLKSEL |= 0x80; //set PLLCLK as sysclk
- }
- /************************************************************/
- /* 初始化ECT模塊 */
- /************************************************************/
- void initialize_ect(void){
- TSCR1_TFFCA = 1; // 定時器標志位快速清除
- TSCR1_TEN = 1; // 定時器使能位. 1=允許定時器正常工作; 0=使主定時器不起作用(包括計數器)
- TIOS = 0xff; //指定所有通道為輸出比較方式
- TCTL1 = 0x00; // 后四個通道設置為定時器與輸出引腳斷開
- TCTL2 = 0x00; // 前四個通道設置為定時器與輸出引腳斷開
- TIE = 0x00; // 禁止所有通道定時中斷
- TSCR2 = 0x07; // 預分頻系數pr2-pr0:111,,時鐘周期為4us,
- TFLG1 = 0xff; // 清除各IC/OC中斷標志位
- TFLG2 = 0xff; // 清除自由定時器中斷標志位
- }
- /*************************************************************/
- /* 初始化按鍵 */
- /*************************************************************/
- void init_key(void)
- {
- KEY1_dir =0; //設置為輸入
- KEY2_dir=0;
- PPSH = 0x00; //極性選擇寄存器,選擇下降沿;
- PIFH = 0x0C; //對PIFH的每一位寫1來清除標志位;
- PIEH = 0x0C; //中斷使能寄存器;
- }
- /*************************************************************/
- /* 按鍵中斷函數 */
- /*************************************************************/
- #pragma CODE_SEG __NEAR_SEG NON_BANKED
- interrupt void PTH_inter(void)
- {
- if(PIFH != 0) //判斷中斷標志
- {
- PIFH = 0xff; //清除中斷標志
- if(KEY2 == 0)
- {
- delay1ms(5);
- if(KEY2 == 0)
- {
- if(single == 0)
- single = 10;
- else single-=1;
-
- }
- }
- if(KEY1 == 0)
- {
- delay1ms(5);
- if(KEY1 == 0)
- {
- if(single == 10)
- single = 0;
- else single+=1;
- }
-
- }
-
- lcd_clear();
- if(single == 0) {
- lcd_string(0,2,poem[0]);
- lcd_string(1,3,poem[1]);
- lcd_string(2,0,poem[2]);
- lcd_string(3,0,poem[3]);
- }
- else if(single == 1) {
- lcd_string(0,3,poem[1]);
- lcd_string(1,0,poem[2]);
- lcd_string(2,0,poem[3]);
- lcd_string(3,0,poem[4]);
- }
- else if(single == 2) {
- lcd_string(0,0,poem[2]);
- lcd_string(1,0,poem[3]);
- lcd_string(2,0,poem[4]);
- lcd_string(3,0,poem[5]);
- }
- else if(single == 8) {
- lcd_string(0,0,poem[8]);
- lcd_string(1,0,poem[9]);
- lcd_string(2,0,poem[10]);
- lcd_string(3,2,poem[0]);
- }
- else if(single == 9) {
- lcd_string(0,0,poem[9]);
- lcd_string(1,0,poem[10]);
- lcd_string(2,2,poem[0]);
- lcd_string(3,3,poem[1]);
- }
- else if(single == 10) {
- lcd_string(0,0,poem[10]);
- lcd_string(1,2,poem[0]);
- lcd_string(2,3,poem[1]);
- lcd_string(3,0,poem[2]);
- }
- else {
- lcd_string(0,0,poem[single]);
- lcd_string(1,0,poem[single + 1]);
- lcd_string(2,0,poem[single + 2]);
- lcd_string(3,0,poem[single + 3]);
- }
- }
- }
- #pragma CODE_SEG DEFAULT
- /*************************************************************/
- /* 主函數 */
- ……………………
- …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼
完整代碼下載:
20并口液晶.rar
(238.55 KB, 下載次數: 28)
2017-10-24 15:18 上傳
點擊文件名下載附件
程序源碼 下載積分: 黑幣 -5
|