今天主要写了三个程序,是老师之前布置得一秒定时切换图片,滑屏切换图片和按键切换图片三个程序,主要涉及到的之前的知识点有定时器中断,按键中断,adc转换,触摸屏,和lcd图片显示
开始觉得内容比较多,而且只是比较散碎,毫无头绪,但是分开到某一项功能细化知识点思路就比较清晰了
定时器的只需要初始化定时器、将图片显示部分写到中断服务当中就可以了
触摸屏切换需要做初始化触摸屏,adc转换,等待触屏中断,判断左右滑动,然后显示图片
而按键切换图片相对比较简单了,只需要配置按键中断,然后将图片显示部分放到中断服务当中去
而最繁琐的还是屏幕驱动部分,寄存器数量多且功能繁琐,还需要时间来慢慢消化
另外一部分是汉字在屏幕上的显示,需要先查到汉字的区位码,然后调用函数即可显示
code
按键切换
#define GLOBAL_CLK 1
#include <stdlib.h>
#include <string.h>
#include "def.h"
#include "option.h"
#include "2440addr.h"
#include "2440lib.h"
#include "2440slib.h"
#include "mmu.h"
#include "profile.h"
#include "lcd.h"
#include "memtest.h"
#include "bmp.h"
void key_init(void);
static void __irq key_handler(void);
extern void show_pic();
unsigned int value;
extern unsigned char gImage_mei[153608];
extern unsigned char gImage_mein[153608];
extern unsigned char gImage_li[153608];
extern unsigned char gImage_lii[153608];
extern unsigned char gImage_liii[153608];
static void __irq key1_irq(void);
static void __irq key2_irq(void);
int i = 0;
//按键初始化
void key_init(void)
{
rGPGCON &= ~((0x3<<0)|(0x3<<6)|(0x3<<10) );
rGPGCON |= ((0x2<<0)|(0x2<<6)|(0x2<<10) ); // 设置成第三功能模式
rEXTINT1 &= ~((0xf<<0)|(0xf<<12)|(0xf<<20) ); // 触发条件
//rEXTINT2 &= ~(0xf<<12);
rEINTPEND |= ((0x1<<8)|(0x1<<11)|(0x1<<13) ); // 清中断标志 写1
rEINTMASK &= ~((0x1<<8)|(0x1<<11)|(0x1<<13) ); // 打开中断屏蔽字 开中断
/*设置ISR*/
pISR_EINT8_23=(U32)key_handler;// 注册中断向量
EnableIrq(BIT_EINT8_23);
}
/*************************************************
按键中断处理函数
**************************************************/
static void __irq key_handler(void)
{
if(rINTPND==BIT_EINT8_23) /*判断是否是按键K1产生的中断*/
{
ClearPending(BIT_EINT8_23); //清除源中断标志
value=rEINTPEND & 0xffffffff; //取中断位 下面判断
//rEINTPEND = rEINTPEND;
//Led1_run();
if(value&(1<<8)) //键1中断
{
rEINTPEND = 0xffffffff; //写1清标?
rGPBDAT = 0xfffffffe;
i = i - 1;
if(i == -1)
{
i = 4;
}
}
if(value&(1<<11)) //键2中断
{
rEINTPEND = 0xffffffff; //|= 1<< 11; //清标志位
rGPBDAT = 0xfffffffe;;
i = i + 1;
if(i == 5)
{
i = 0;
}
}
}
if(i == 5)
{
i = 0;
}
show_pic(i);
}
int Main()
{
MMU_Init();
key_init();
Port_Init();
for (;;);
}
#define GLOBAL_CLK 1
#include <stdlib.h>
#include <string.h>
#include "def.h"
#include "option.h"
#include "2440addr.h"
#include "2440lib.h"
#include "2440slib.h"
#include "mmu.h"
#include "profile.h"
#include "lcd.h"
#include "bmp.h"
unsigned int value;
extern unsigned char gImage_mei[153608];
extern unsigned char gImage_mein[153608];
extern unsigned char gImage_li[153608];
extern unsigned char gImage_lii[153608];
extern unsigned char gImage_liii[153608];
static void __irq Timer1_irq(void);
extern void show_pic();
int i = 0;
//计时器初始化
void Timer1_Init()
{
rTCFG0 = 0X0F9; //timer1
rTCFG1 = 0x030;
rTCNTB1 = 12500;// 1s定时
rTCMPB1 = 12500/2; //
rTCON = 0x0200;//
rTCON = 0x0900; //
ClearPending(BIT_TIMER1);
pISR_TIMER1 = (U32)Timer1_irq; //
EnableIrq(BIT_TIMER1); //
}
//主函数
int Main()
{
MMU_Init();
Port_Init();
Timer1_Init();
for (;;);
}
//中断服务程序
static void __irq Timer1_irq(void)
{
if(i == 5)
{
i = 0;
}
ClearPending(BIT_TIMER1);
show_pic(i);
i = i +1;
}
滑屏切换
#define GLOBAL_CLK 1
#include <stdlib.h>
#include <string.h>
#include "def.h"
#include "option.h"
#include "2440addr.h"
#include "2440lib.h"
#include "2440slib.h"
#include "mmu.h"
#include "profile.h"
#include "lcd.h"
#include "memtest.h"
#include "bmp.h"
unsigned int value;
extern unsigned char gImage_mei[153608];
extern unsigned char gImage_mein[153608];
extern unsigned char gImage_li[153608];
extern unsigned char gImage_lii[153608];
extern unsigned char gImage_liii[153608];
// static void __irq Timer1_irq(void);
int k = 0;
#define TXD0READY (1<<2) //发送数据状态OK
#define RXD0READY (1) //接收数据状态OK
#define ADC_FREQ 2500000 //定义
volatile U32 preScaler;
volatile U32 adc_value=0;
int count = 0;
int xdata,ydata;
static int x;
static int y;
void adc_init(void);
int ReadAdc(int channel);
static void __irq AdcTsAuto(void);
void Test_Touchpanel(void);
extern void show_pic();
/*延时函数*/
__inline void delay(int msec)
{
int i, j;
for(i = 1000; i > 0; i--)
for(j = msec*10; j > 0; j--)
/* do nothing */;
}
/*触摸屏初始化*/
void Test_Touchpanel(void)
{
preScaler = 50000000/ADC_FREQ - 1; //预分频值为19
rADCDLY = 50000; //Normal conversion mode delay about (1/3.6864M)*50000 = 13.56ms
rADCCON = (1<<14)|(preScaler<<6); //ADCPRS En, ADCPRS Value
Uart_Printf("ADC touch screen test\n");
rADCTSC = 0xd3; //Wfait,XP_PU,XP_Dis,XM_Dis,YP_Dis,YM_En
pISR_ADC = (int)AdcTsAuto;
rINTMSK = ~BIT_ADC; //清触摸屏标记位
rINTSUBMSK = ~(BIT_SUB_TC); //清子中断标记位
Uart_Printf("\nType any key to exit!!!\n");
Uart_Printf("\nStylus Down, please...... \n");
Uart_Getch();
}
/*中断服务程序*/
void __irq AdcTsAuto(void)
{
int tmpx,tmpy;
U32 saveAdcdly;
rADCTSC = (1<<3)|(1<<2); //上拉无效,正常ADC转换
saveAdcdly = rADCDLY;
rADCDLY = 40000; //正常转换模式每次大约0.8ms
rADCCON |= 0x1; //开始转换
while(rADCCON & 0x1); //检查是否开始转换
while(!(rADCCON & 0x8000)); //检查转换是否结束
while(!(rSRCPND & (BIT_ADC))); //检查是否有ADC的中断请求
rSUBSRCPND |= BIT_SUB_TC;
ClearPending(BIT_ADC);
rINTSUBMSK = ~(BIT_SUB_TC);
rINTMSK = ~(BIT_ADC);
x = (rADCDAT0&0x3ff);
y = (rADCDAT1&0x3ff);
while(1) //to check Pen-up state
{
rADCTSC = (1<<3)|(1<<2); //上拉无效,正常ADC转换
saveAdcdly = rADCDLY;
rADCDLY = 80000; //正常转换模式每次大约0.8ms
rADCCON |= 0x1; //开始转换
while(rADCCON & 0x1); //检查是否开始转换
while(!(rADCCON & 0x8000)); //检查转换是否结束
xdata = (rADCDAT0&0x3ff);
ydata = (rADCDAT1&0x3ff);
if(xdata==tmpx&&ydata==tmpy)break;
tmpx=xdata;
tmpy=ydata;
}
if(xdata>x)
{
k = k +1;
if(k >= 5)
{
k = 0;
}
}
else if(xdata<x)
{
k = k -1;
if(k <= -1)
{
k = 4;
}
}
show_pic(k);
rADCDLY = saveAdcdly;
rADCTSC=0xd3; //Wfait,XP_PU,XP_Dis,XM_Dis,YP_Dis,YM_En
rSUBSRCPND |= BIT_SUB_TC;
rINTSUBMSK = ~(BIT_SUB_TC); // Unmask sub interrupt (TC)
ClearPending(BIT_ADC);
}
int Main()
{
MMU_Init();
Test_Touchpanel();
Port_Init();
while(1);
return 0;
}
汉字显示
{
unsigned short int i,j;
unsigned char *pZK,mask,buf;
pZK = &__CHS[ ( ( (QW >> 8) - 1 )*94 + (QW & 0x00FF)- 1 )*32 ];
for( i = 0 ; i < 16 ; i++ )
{
//×ó
mask = 0x80;
buf = pZK[i*2];
for( j = 0 ; j < 8 ; j++ )
{
if( buf & mask )
{
PutPixel(x+j,y+i,c);
}else
{
if( !st )
{
PutPixel(x+j,y+i,bk_c);
}
}
mask = mask >> 1;
}
//ÓÒ
mask = 0x80;
buf = pZK[i*2 + 1];
for( j = 0 ; j < 8 ; j++ )
{
if( buf & mask )
{
PutPixel(x+j + 8,y+i,c);
}else
{
if( !st )
{
PutPixel(x+j + 8,y+i,bk_c);
}
}
mask = mask >> 1;
}
}
}
/**********************************
´òÓ¡×Ô¼ºµÄÃû×Ö
**********************************/
void Put_Name()
{
PutHZ(190,300,0x192B,0x000F,0x3f << 5,0);
PutHZ(206,300,0x181B,0x000F,0x3f << 5,0);
PutHZ(222,300,0x1942,0x000F,0x3f << 5,0);
}
本文介绍了在嵌入式系统中通过按键、定时器和触摸屏实现LCD屏幕图片切换的方法,涉及定时器中断、按键中断、ADC转换、触摸屏和LCD显示等技术。通过代码展示了按键切换、定时器切换和滑屏切换图片的实现过程。
4257

被折叠的 条评论
为什么被折叠?



