📄 beepon.c
字号:
#include <includes.h>
#include <LPC21xx.H> /* LPC21xx definitions */
#define BEEPCON 0x80000000 /*P0.7 引脚控制B1,低电平蜂鸣*/
#define safe 0x00000800 /*p0.11绿灯亮 低电平亮*/
#define danger 0x00001000 /*p0.12红灯亮*/
#define LCD_BL 0x00800000 /*P0.23背光高电平亮 */
#define GUI_LCM_XMAX 128 /* 定义液晶x轴的点数 */
#define GUI_LCM_YMAX 64 /* 定义液晶y轴的点数 */
//IODIR1=IODIR1|0xFFFF0000; 使用P1 口时用这种办法改变输入输出方向
//IOSET1=0xB1AA0000 ;
/* 硬件连接: D0--D7 <===> P1.16--P1.23 PINSEL2 =0x0008H P1:25:16 用作GPIO 管脚。
* LCD_DIR <---> P0.22
* LCD_BL <--> P0.23
* /WR <===> P0.27
* /RD <===> P0.28
* /CE <===> P0.29
* C/D <===> P1.27/TDO 跳线
* /RST <===> P1.24*/
#define LCD_WR 0x08000000
#define LCD_RD 0x10000000
#define LCD_CE 0x20000000
#define LCD_CD 0x08000000
#define LCD_RST 0x01000000
#define LCD_DIR 0x00400000
/* T6963C 命令定义 */
#define LCD_CUR_POS 0x21 /* 光标位置设置(只有设置到有效显示地址并打开显示时才看到) */
#define LCD_CGR_POS 0x22 /* CGRAM偏置地址设置(可以增加自已的符号) */
#define LCD_ADR_POS 0x24 /* 地址指针位置(设置读写操作指针) */
#define LCD_TXT_STP 0x40 /* 文本区首址(从此地址开始向屏幕左上角显示字符) */
#define LCD_TXT_WID 0x41 /* 文本区宽度(设置显示宽度,N/6或N/8,其中N为x轴的点数) */
#define LCD_GRH_STP 0x42 /* 图形区首址(从此地址开始向屏幕左上角显示点) */
#define LCD_GRH_WID 0x43 /* 图形区宽度(设置显示宽度,N/6或N/8,其中N为x轴的点数) */
#define LCD_MOD_OR 0x80 /* 显示方式:逻辑或 */
#define LCD_MOD_XOR 0x81 /* 显示方式:逻辑异或 */
#define LCD_MOD_AND 0x82 /* 显示方式:逻辑与 */
#define LCD_MOD_TCH 0x83 /* 显示方式:文本特征 */
#define LCD_DIS_SW 0x90 /* 显示开关:D0=1/0,光标闪烁启用/禁用 */
/* D1=1/0,光标显示启用/禁用 */
/* D2=1/0,文本显示启用/禁用(打开后再使用) */
/* D3=1/0,图形显示启用/禁用(打开后再使用) */
#define LCD_CUR_SHP 0xA0 /* 光标形状选择:0xA0-0xA7表示光标占的行数 */
#define LCD_AUT_WR 0xB0 /* 自动写设置 */
#define LCD_AUT_RD 0xB1 /* 自动读设置 */
#define LCD_AUT_OVR 0xB2 /* 自动读/写结束 */
#define LCD_INC_WR 0xC0 /* 数据一次写,地址加1 */
#define LCD_INC_RD 0xC1 /* 数据一次读,地址加1 */
#define LCD_DEC_WR 0xC2 /* 数据一次写,地址减1 */
#define LCD_DEC_RD 0xC3 /* 数据一次读,地址减1 */
#define LCD_NOC_WR 0xC4 /* 数据一次写,地址不变 */
#define LCD_NOC_RD 0xC5 /* 数据一次读,地址不变 */
#define LCD_SCN_RD 0xE0 /* 屏读 */
#define LCD_SCN_CP 0xE8 /* 屏拷贝 */
#define LCD_BIT_OP 0xF0 /* 位操作:D0-D2--定义D0-D7位,D3--1为置位,0为清除 */
uint8 gui_disp_buf[GUI_LCM_YMAX][GUI_LCM_XMAX/8];
/************************************************
* 名称:DelayNS()
* 功能:长软件延时
* 入口参数:dly 延时参数,值越大,延时越长
* 出口参数:无
***************************************************/
extern void DelayNs(uint32 dly);
extern void LCD_WriteData(uint8 lcddat);
extern void LCD_FillAll(uint8 dat);
extern uint8 LCD_ReadData();
extern void LCD_UpdatePoint(uint32 x, uint32 y);
extern uint8 LCD_WriteTCommand2(uint8 command, uint8 dat1);
extern void LCD_Initialize(void);
extern uint8 LCD_ReadState(void);
extern uint8 LCD_WriteTCommand3(uint8 command, uint8 dat1, uint8 dat2);
extern uint8 LCD_WriteTCommand2(uint8 command, uint8 dat1) ;
extern uint8 LCD_WriteTCommand1(uint8 command);
extern uint8 LCD_RTCommand1(uint8 command);
extern uint8 LCD_WriteTData1(uint8 dat);
extern uint8 display_date(uint8 * Disp_date);
extern uint8 display_time(uint8 * Disp_time);
extern uint8 display_speed(uint8 * Disp_speed);
extern void TimeInit(void);
//extern void irq1(void)__irq;
//extern void irq2(void);
extern void ClkInit();
void DelayNs2(uint32 dly)
{ uint32 i;
for(;dly>0;dly--)
for(i=0;i<1000;i++);}
/***********************************
*名称: main()
*
********************************************/
uint8 count=0;
uint16 frequence; //存储T0计数值
int main(void)
{
uint32 i;
uint8 j;
uint32 addr1;
uint8 k;
uint8 speed; //存储转换后的车速
uint16 m[6];
uint8 temp;
uint32 times,dates;
// uint8 temp;
uint8 dat;
uint8 datesz[8] ;
uint8 timesz[6];
uint8 speedsz[3];
uint8 Matrixdate[90]=
{
/*------------------------------------------------------------------------------
; 源文件 / 文字: "日期:"
; 宽×高(像素) : 18×39 横向5个字节
------------------------------------------------------------------------------*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x10,0x24,0x08,0x00,0x1F,
0xF8,0x24,0xFC,0x00,0x10,0x10,0x7E,0x88,
0x00,0x10,0x10,0x24,0x88,0x00,0x10,0x10,
0x3C,0xF8,0x00,0x10,0x10,0x24,0x88,0x10,
0x1F,0xF0,0x24,0x88,0x10,0x10,0x10,0x3C,
0x88,0x00,0x10,0x10,0x24,0xF8,0x00,0x10,
0x10,0xFE,0x88,0x00,0x10,0x10,0x14,0x88,
0x00,0x1F,0xF0,0x22,0x88,0x10,0x10,0x10,
0x41,0x28,0x10,0x10,0x10,0x82,0x10,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00
};
uint8 Matrixtime[90] =
{
/*------------------------------------------------------------------------------
; 源文件 / 文字: 时间:
; 宽×高(像素) : 18×39
------------------------------------------------------------------------------*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x20,0x20,0x08,0x00,0x00,
0x20,0x17,0xFC,0x00,0x78,0x20,0x50,0x08,
0x00,0x4B,0xFC,0x40,0x08,0x00,0x48,0x20,
0x47,0xC8,0x00,0x48,0x20,0x44,0x48,0x10,
0x79,0x20,0x44,0x48,0x10,0x48,0xA0,0x47,
0xC8,0x00,0x48,0xA0,0x44,0x48,0x00,0x48,
0x20,0x44,0x48,0x00,0x78,0x20,0x47,0xC8,
0x00,0x48,0x20,0x40,0x08,0x10,0x40,0xA0,
0x40,0x28,0x10,0x00,0x40,0x40,0x10,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00
};
uint8 Matrixspeed[90] =
{
/*------------------------------------------------------------------------------
; 源文件 / 文字: 速度:
; 宽×高(像素) : 18×39
------------------------------------------------------------------------------*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x40,0x80,0x01,0x00,0x00,0x20,
0x88,0x00,0x88,0x00,0x2F,0xFC,0x3F,0xFC,
0x00,0x00,0x80,0x22,0x20,0x00,0x07,0xF0,
0x2F,0xF8,0x00,0xE4,0x90,0x22,0x20,0x10,
0x27,0xF0,0x23,0xE0,0x10,0x20,0xC0,0x20,
0x00,0x00,0x21,0xA0,0x2F,0xF0,0x00,0x22,
0x90,0x22,0x20,0x00,0x24,0x88,0x21,0x40,
0x00,0x50,0x80,0x40,0x80,0x10,0x88,0x00,
0x43,0x60,0x10,0x07,0xFC,0x9C,0x1C,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00
};
uint8 Matrixxie[17]=
{
/*------------------------------------------------------------------------------
; 源文件 / 文字: /
; 宽×高(像素) : 18×7
------------------------------------------------------------------------------*/
0x00,0x00,0x02,0x04,0x04,0x04,0x08,
0x08,0x10,0x10,0x20,0x20,0x40,0x40,0x40,
0x80,0x00
};
uint8 MatrixMaohao[12]=
{
/*------------------------------------------------------------------------------
; 源文件 / 文字: :
; 宽×高(像素) : 18×7
------------------------------------------------------------------------------*/
0x00,0x00,
0x00,0x10,0x10,0x00,0x00,0x10,0x10,0x00,
0x00,0x00
};
uint8 Matrixkmh[90] =
{
/*------------------------------------------------------------------------------
; 源文件 / 文字: km/h
; 宽×高(像素) : 18×40
------------------------------------------------------------------------------*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,
0x00,0x00,0x02,0x80,0x40,0x00,0x00,0x04,
0x80,0x40,0x00,0x00,0x04,0x80,0x40,0x00,
0x00,0x04,0x80,0x42,0x17,0x38,0x08,0xBC,
0x44,0x18,0xC4,0x08,0xC2,0x48,0x10,0x84,
0x10,0x82,0x50,0x10,0x84,0x10,0x82,0x68,
0x10,0x84,0x20,0x82,0x44,0x10,0x84,0x20,
0x82,0x42,0x10,0x84,0x40,0x82,0x41,0x10,
0x84,0x40,0x82,0x00,0x00,0x00,0x40,0x00,
0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,
0x00,0x00
};
DelayNs(6000); //延时为LCD作准备
/*引脚定义*/
PINSEL0=0x00000005;
PINSEL1=0x00000000|0x20000000; //设置P0.30为CAP0.0; //设置引脚连接GPIO
PINSEL2=PINSEL2&0xFFFFFF03; //P1.16-P1.31均设置为GPIO
EXTMODE=0x08;
IODIR0= LCD_WR|LCD_RD|LCD_CE|BEEPCON|safe|danger|LCD_DIR|LCD_BL ;
IODIR1=IODIR1|0xFFFF0000; //P1口暂时定义全为 输出 使用时记得修改
IOCLR1|=LCD_RST; //重置LCD
IOSET0=IOSET0|BEEPCON; //禁止 蜂鸣
IOCLR0=IOCLR0|safe;
IOCLR0|=danger;
DelayNs(1000);
IOSET1|=LCD_RST;
/*for(i=0;i<2;i++)
{
IOSET0|=safe;
IOSET0|=danger;
DelayNs(4000);
IOCLR0|=safe;
DelayNs(4000);
IOCLR0|=danger;
DelayNs(4000);
}
IOCLR0=IOCLR0|LCD_BL;
DelayNs(4000); */
/***************初始化***********************/
TimeInit(); //计数器初始化
ClkInit();
//实时时钟初始化
DelayNs2(4000);
LCD_Initialize(); //LCD初始化
LCD_FillAll(0x00); //清屏
IOCLR1=IOCLR1&0xFF00FFFF;
IOSET0|=safe;
IOSET0|=danger;
IOCLR0|=LCD_DIR;
/*****************显示汉字“日期:”*****************************/
LCD_WriteTCommand3(LCD_ADR_POS, 0x00, 0x00); // 置地址指针
i=0;
dat=Matrixdate[i] ;
for(k=0;k<18;k++)
{for(j=0;j<5;j++)
{addr1=k*16+j;
LCD_WriteTCommand3(LCD_ADR_POS, addr1&0xFF, addr1>>8); // 置地址指针
LCD_WriteTCommand2(LCD_NOC_WR, dat);
dat=Matrixdate[i] ;
i++;}
}
display_date(datesz); //显示日期数字
/*********************显示日期:”end ********************************/
/*****************显示汉字“时间:”*****************************/
LCD_WriteTCommand3(LCD_ADR_POS, 0x00, 0x00); // 置地址指针
i=0;
dat=Matrixtime[i] ;
for(k=18;k<36;k++)
{for(j=0;j<5;j++)
{addr1=k*16+j;
LCD_WriteTCommand3(LCD_ADR_POS, addr1&0xFF, addr1>>8); // 置地址指针
LCD_WriteTCommand2(LCD_NOC_WR, dat);
dat=Matrixtime[i] ;
i++;}
}
display_time(timesz); //显示时间数字
/*********************显示“时间:”end ********************************/
/*****************显示汉字“速度:”*****************************/
LCD_WriteTCommand3(LCD_ADR_POS, 0x00, 0x00); // 置地址指针
i=0;
dat=Matrixspeed[i] ;
for(k=36;k<54;k++)
{for(j=0;j<5;j++)
{addr1=k*16+j;
LCD_WriteTCommand3(LCD_ADR_POS, addr1&0xFF, addr1>>8); // 置地址指针
LCD_WriteTCommand2(LCD_NOC_WR, dat);
dat=Matrixspeed[i] ;
i++;}
}
display_speed(speedsz); //显示速度数据
/*********************显示“速度:”end ********************************/
/*****************显示km/h:”*****************************/
LCD_WriteTCommand3(LCD_ADR_POS, 0x00, 0x00); // 置地址指针
i=0;
dat=Matrixkmh[i] ;
for(k=36;k<54;k++)
{for(j=11;j<16;j++)
{addr1=k*16+j;
LCD_WriteTCommand3(LCD_ADR_POS, addr1&0xFF, addr1>>8); // 置地址指针
LCD_WriteTCommand2(LCD_NOC_WR, dat);
dat=Matrixkmh[i] ;
i++;}
}
/*********************显示km/h end ********************************/
/************测速及显示时间********************/
while(1)
{ if(EXTINT==0x08)
{EXTINT=0x08; //采用外部中断计数
count=count++;}
if(T1IR==0x01)
{T1IR=0x01;
frequence=count;
count=0;
if (frequence<=250) //转换车速
{ IOCLR0=IOCLR0|safe;
speed=(frequence*100)/250;
if (speed>=100) //车速值输出转换
{
speedsz[2]=speed/100;
temp=speed%100;
speedsz[1]=temp/10;
temp=temp%10;
speedsz[0]=temp;
}
else
{
speedsz[2]=0;
speedsz[1]=speed/10;
speedsz[0]=speed%10;
}
times=CTIME0;
dates=CTIME1;
m[0]=speed;
m[1]= (dates>>16)&0xFFF;
datesz[7]=2;
datesz[6]=0;
datesz[5]=0;
datesz[4]=7;
m[2]=(dates>>8)&0x0F;
if(m[2]>=10)
{
datesz[3]=m[2]/10;
datesz[2]=m[2]%10;
}
else
{ datesz[2]=m[2];
datesz[3]=0;}
m[3]= dates&0x1F;
if(m[3]>=10)
{
datesz[1]=m[3]/10;
datesz[0]=m[3]%10;
}
else
{
datesz[0]=m[3];
datesz[1]=0;
}
if((datesz[7]!=2)||(datesz[6]!=0)||(datesz[5]!=0)||(datesz[4]!=7)||(datesz[3]!=0)||(datesz[2]!=1)||(datesz[1]!=2)||(datesz[0]!=0))
{display_date(datesz); //显示日期数字
}
m[4]= (times>>16)&0x1F;
if(m[4]>=10)
{
timesz[5]=m[4]/10;
timesz[4]=m[4]%10;
}
else
{
timesz[4]=m[4];
timesz[5]=0;
}
m[5]= (times>>8)&0x3F;
if(m[5]>=10)
{
timesz[3]=m[5]/10;
timesz[2]=m[5]%10;
}
else
{
timesz[2]=m[5];
timesz[3]=0;
}
m[6]= times&0x3F;
if(m[6]>=10)
{
timesz[1]=m[6]/10;
timesz[0]=m[6]%10;
}
else
{
timesz[0]=m[6];
timesz[1]=0;
}
}
else
{
IOCLR0=IOCLR0|danger|BEEPCON;
}
// 此处在调用错误显示程序
display_time(timesz); //显示时间数字
display_speed(speedsz); //显示速度数据
//display_date(datesz); //显示日期数字
//return (1);
}
}
return(1);
}
/***********此注释程序为测试IO口程序*****************
IODIR0=0x00801800; //设置I/O为输出
//IODIR0=LCD_BL;
IOCLR0=LCD_BL;
DelayNs(10000);
for(i=0;i<5;i++)
{
IOCLR0=safe; //绿灯亮
DelayNs(3000);
IOSET0=safe ;
DelayNs(3000);
IOCLR0=safe; //绿灯亮
DelayNs(3000);
IOCLR0=danger; // 红灯亮
DelayNs(1000);
//IOSET0=BEEPCON; //BEEPCON=1
//DelayNs(10000);
//IOCLR0=BEEPCON; //BEEPCON=0
// DelayNs(10000);
IOSET0=safe ;
DelayNs(3000);
IOSET0=danger;
DelayNs(3000);
IOSET0=LCD_BL;
DelayNs(10000);
}
return(0); ******************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -