📄 fun_vic.c
字号:
/******************************Copyright (c)*********************************
** File Infomation
**---------------------------------------------------------------------------
**文 件 名: fun_vic.c
**创 建 人: 杨宏伟(YGRAND)
**创 建 日 期:2003年10月19日
**最后修改日期: 2004年09月08日
**描 述: 中断处理等函数定义,FOR ARM LPC2114
****************************************************************************/
#include "config.h"
extern uint8 G_FLAG; // 全局变量,作为判断暂停或继续的标志
extern uint8 G_STEP_VALUE; // 全局变量,存储步值
extern uint8 G_CurrContrastValue;
extern uint8 G_CurrContrastValue_S;
extern void comm_out(uint8 i);
extern void data_out(uint16 i);
extern void delay(uint32 dly);
extern void reset(void);
extern void dispByStep(uint8 step);
extern void beep(uint8 port,uint32 beep_bit,uint8 count,uint8 dly);
extern void adjustContrast(uint8 type);
extern void dispContrastToLcd(uint16 x,uint16 y, uint16 FColorA,uint16 FColorB,uint16 BColorA,uint16 BColorB,uint8 value);
extern void dispContrastToLcd_s(uint16 x,uint16 y, uint16 FColorA,uint16 FColorB,uint16 BColorA,uint16 BColorB,uint8 value);
extern void adjustContrast_s(uint8 type);
extern signed G_OTP_OFFSET;
/********************F********************************************************
** Function 函数定义
*****************************************************************************/
/*===========================================================================
** 函数名称: __irq IRQ_Eint0()
** 功能描述: 外部中断EINT0服务函数,实现暂停/继续功能,P0.16-KEY1
** 输 入: 无
** 输 出: 无
** 全局变量: G_FLAG-作为判断暂停或继续的标志
============================================================================*/
void __irq IRQ_Eint0(void)
{
uint32 i;
i = VICIRQStatus; // 读出VICIRQStatus的值
IO1SET = CS1;
IO1SET = CS1_S;
IO0SET = (1<<23)|(1<<24)|(1<<25); // LED2,LED3,LED4灭
beep(1,BEEP_BIT,1,10);
while( (EXTINT&0x01)!=0 ) // 等待外部中断信号恢复为高电平
{
EXTINT = 0x01; // 清除EINT0中断标志
dispContrastToLcd(0,0,0x00,0x1f,0xff,0xff,G_CurrContrastValue);
dispContrastToLcd_s(0,0,0x00,0x00,0xff,0xff,G_CurrContrastValue_S);
}
G_FLAG=~G_FLAG;
if(G_FLAG&0x01!=0)
{
while((EXTINT&0x01)==0);
}
IO0CLR = (1<<23)|(1<<24)|(1<<25); // LED2,LED3,LED4亮
VICVectAddr = 0x00;
}
/*===========================================================================
** 函数名称: __irq IRQ_Eint1()
** 功能描述: 外部中断EINT1服务函数
** 输 入: 无
** 输 出: 无
============================================================================*/
void __irq IRQ_Eint1(void)
{
}
/*===========================================================================
** 函数名称: __irq IRQ_Eint2()
** 功能描述: 外部中断EINT2服务函数
** 输 入: 无
** 输 出: 无
============================================================================*/
void __irq IRQ_Eint2(void)
{
}
/*===========================================================================
** 函数名称: __irq IRQ_T0()
** 功能描述: T0中断服务函数
** 输 入: 无
** 输 出: 无
============================================================================*/
void __irq IRQ_T0(void)
{
IO0DIR = ~((1<<17)|(1<<18)|(1<<19)|(1<<20)|(1<<21));
//display by step
if( (IOPIN&(1<<17))==0 ) // P0.17,key2, <<
{
if(G_STEP_VALUE>0)
{
G_STEP_VALUE --;
}
else
{
G_STEP_VALUE = G_STEP_VALUE_MAX;
}
dispByStep(G_STEP_VALUE);
}
if( (IOPIN&(1<<18))==0 ) // P0.18,key3, >>
{
if(G_STEP_VALUE<G_STEP_VALUE_MAX)
{
G_STEP_VALUE ++;
}
else
{
G_STEP_VALUE = 0;
}
dispByStep(G_STEP_VALUE);
}
//adjust contrast
if( (IOPIN&(1<<19))==0 ) // P0.19,key4, --
{
IO1SET = CS1_S;
G_OTP_OFFSET --;
adjustContrast(0);
}
if( (IOPIN&(1<<20))==0 ) // P0.20,key5, ++
{
IO1SET = CS1_S;
G_OTP_OFFSET ++;
adjustContrast(1);
}
// OTP
if( (IOPIN&(1<<21))==0 ) // P0.21,key6
{
IO0SET = (1<<22); // LED1灭
G_FLAG=~G_FLAG;
if(G_FLAG&0x01!=0)
{
beep(1,BEEP_BIT,1,20);
reset();
comm_out(0xD1);
comm_out(0x94);
delay(100);
IO1SET = C_VDD;
IO1CLR = C_GND;
delay(100);
}
else
{
beep(1,BEEP_BIT,2,20);
//OTP write
switch(G_OTP_OFFSET)
{
case -16:
comm_out(0xF6);
data_out(0x18);
data_out(0x0a);
break;
case -15:
comm_out(0xF6);
data_out(0x18);
data_out(0x2a);
break;
case -14:
comm_out(0xF6);
data_out(0x19);
data_out(0x0a);
break;
case -13:
comm_out(0xF6);
data_out(0x19);
data_out(0x2a);
break;
case -12:
comm_out(0xF6);
data_out(0x1a);
data_out(0x0a);
break;
case -11:
comm_out(0xF6);
data_out(0x1a);
data_out(0x2a);
break;
case -10:
comm_out(0xF6);
data_out(0x1b);
data_out(0x0a);
break;
case -9:
comm_out(0xF6);
data_out(0x1b);
data_out(0x2a);
break;
case -8:
comm_out(0xF6);
data_out(0x1c);
data_out(0x0a);
break;
case -7:
comm_out(0xF6);
data_out(0x1c);
data_out(0x2a);
break;
case -6:
comm_out(0xF6);
data_out(0x1d);
data_out(0x0a);
break;
case -5:
comm_out(0xF6);
data_out(0x1d);
data_out(0x2a);
break;
case -4:
comm_out(0xF6);
data_out(0x1e);
data_out(0x0a);
break;
case -3:
comm_out(0xF6);
data_out(0x1e);
data_out(0x2a);
break;
case -2:
comm_out(0xF6);
data_out(0x1f);
data_out(0x0a);
break;
case -1:
comm_out(0xF6);
data_out(0x1f);
data_out(0x2a);
break;
case 0:
;
break;
case 1:
comm_out(0xF6);
data_out(0x10);
data_out(0x2a);
break;
case 2:
comm_out(0xF6);
data_out(0x11);
data_out(0x0a);
break;
case 3:
comm_out(0xF6);
data_out(0x11);
data_out(0x2a);
break;
case 4:
comm_out(0xF6);
data_out(0x12);
data_out(0x0a);
break;
case 5:
comm_out(0xF6);
data_out(0x12);
data_out(0x2a);
break;
case 6:
comm_out(0xF6);
data_out(0x13);
data_out(0x0a);
break;
case 7:
comm_out(0xF6);
data_out(0x13);
data_out(0x2a);
break;
case 8:
comm_out(0xF6);
data_out(0x14);
data_out(0x0a);
break;
case 9:
comm_out(0xF6);
data_out(0x14);
data_out(0x2a);
break;
case 10:
comm_out(0xF6);
data_out(0x15);
data_out(0x0a);
break;
case 11:
comm_out(0xF6);
data_out(0x15);
data_out(0x2a);
break;
case 12:
comm_out(0xF6);
data_out(0x16);
data_out(0x0a);
break;
case 13:
comm_out(0xF6);
data_out(0x16);
data_out(0x2a);
break;
case 14:
comm_out(0xF6);
data_out(0x17);
data_out(0x0a);
break;
case 15:
comm_out(0xF6);
data_out(0x17);
data_out(0x2a);
break;
default:
;
}
comm_out(0xF8);
delay(800);
IO1CLR = C_VDD;
IO1SET = C_GND;
delay(100);
//stop OTP write
beep(1,BEEP_BIT,1,80);
}
IO0CLR = (1<<22); // LED1亮
}
T0IR = 0x01; // 清除中断标志
VICVectAddr = 0x00; // 通知VIC中断处理结束
}
/*
void __irq IRQ_T0(void)
{
IO0DIR = ~((1<<17)|(1<<18)|(1<<19)|(1<<20)|(1<<21));
//display by step
if( (IOPIN&(1<<17))==0 ) // P0.17,key2, <<
{
if(G_STEP_VALUE>0)
{
G_STEP_VALUE --;
}
else
{
G_STEP_VALUE = G_STEP_VALUE_MAX;
}
dispByStep(G_STEP_VALUE);
}
if( (IOPIN&(1<<18))==0 ) // P0.18,key3, >>
{
if(G_STEP_VALUE<G_STEP_VALUE_MAX)
{
G_STEP_VALUE ++;
}
else
{
G_STEP_VALUE = 0;
}
dispByStep(G_STEP_VALUE);
}
//adjust contrast
if( (IOPIN&(1<<19))==0 ) // P0.19,key4, --
{
IO1SET = CS1_S;
adjustContrast(0);
}
if( (IOPIN&(1<<20))==0 ) // P0.20,key5, ++
{
IO1SET = CS1_S;
adjustContrast(1);
}
T0IR = 0x01; // 清除中断标志
VICVectAddr = 0x00; // 通知VIC中断处理结束
}
*/
/*===========================================================================
** 函数名称: setVIC()
** 功能描述: 使能EINT0、T0中断
============================================================================*/
void setVIC(void)
{
//初始化定时器0,实现0.5S定时;定时器1实现0.1秒定时。
//Fcclk=Fosc*4=11.0592MHz*4=44.2368MHz
//Fpclk=Fcclk/4=44.2368MHz/4=11.0592MHz
T0PR = 99; // 设置定时器分频为100分频,得110592Hz
T0MCR = 0x03; // 匹配通道0匹配中断并复位T0TC
T0MR0 = 110592/10; // 比较值
T0TCR = 0x03; // 启动并复位T0TC
T0TCR = 0x01;
//T1PR = 99; // 设置定时器分频为100分频,得110592Hz
//T1MCR = 0x02; // 匹配通道0匹配复位T1TC
//T1MR0 = 110592/10; // 比较值
//T1EMR = 0x30; // 设置定时器1的T1MR0匹配输出,输出方式为翻转
//T1TCR = 0x03; // 启动并复位T1TC
//T1TCR = 0x01;
// VIC通道号:EINT2-16
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -