标题:
MC9S12XS128并口12864液晶显示程序,包含按键中断,按键可翻动的程序源码
[打印本页]
作者:
123zyb
时间:
2017-10-24 15:19
标题:
MC9S12XS128并口12864液晶显示程序,包含按键中断,按键可翻动的程序源码
程序在12864液晶上显示一首词,按键可翻动词句。
0.png
(6.42 KB, 下载次数: 79)
下载附件
2017-10-25 00:29 上传
单片机源程序如下:
/*---------------------------------------------------------*/
/************************************************************
飞翔科技MC9S12XS128汽车电子开发板
************************************************************/
/*---------------------------------------------------------*/
#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; //液晶翻页的标志符
/*************************************************************/
/* 初始化锁相环 */
/*************************************************************/
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
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1