📄 main.c
字号:
/****************************************Copyright (c)****************************************************
** Guangzhou ZHIYUAN electronics Co.,LTD.
**
** http://www.embedtools.com
**
**--------------File Info---------------------------------------------------------------------------------
** File name: main.c
** Latest modified Date: 2008-12-14
** Latest Version: v0.1
** Descriptions: 使用I2C方式对ZLG7290实现显示和键盘操作;
** 修改中断使能方法,采用FIQEnable ()、IQREnable ()方式
**
**--------------------------------------------------------------------------------------------------------
** Created by: huangwujiao
** Created date: 2008-11-18
** Version: The original version
** Descriptions:
**
**--------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
*********************************************************************************************************/
#include "config.h"
#define ZLG7290 0x70 /* 定义器件地址 */
/*********************************************************************************************************
** 函数名称:I2C_Init()
** 函数功能:主模式I2C初始化,包括初始化其中断为向量IRQ中断。
** 输入参数:fi2c 初始化I2C总线速率,最大值为400K
** 输出参数:无
*********************************************************************************************************/
void I2C_Init(uint32 fi2c)
{
if(fi2c>400000) fi2c = 400000; /* 判断波特率 */
PINSEL0 = (PINSEL0&0xFFFFFF0F) | 0x50; /* 管脚配置 */
I2SCLH = (Fpclk/fi2c + 1) / 2; /* 设置I2C时钟为fi2c */
I2SCLL = (Fpclk/fi2c) / 2;
I2CONCLR = 0x2C;
I2CONSET = 0x40; /* 使能主I2C */
IRQEnable ();
/*
*设置I2C中断允许
*/
VICIntSelect = 0x00000000; /* 设置所有通道为IRQ中断 */
VICVectCntl0 = 0x29; /* I2C通道分配到IRQ slot 0 */
VICVectAddr0 = (int)IRQ_I2C; /* 设置I2C中断向量地址 */
VICIntEnable = 0x0200; /* 使能I2C中断 */
}
/*********************************************************************************************************
** 函数名称: DelayNS
** 函数功能: 长软件延时
** 输入参数: uiDly 延时参数,值越大,延时越久
** 输出函数: 无
*********************************************************************************************************/
void DelayNS(uint32 uiDly)
{
uint32 i;
for(; uiDly > 0; uiDly--) {
for(i=0; i<50000; i++);
}
}
/*********************************************************************************************************
** 函数名称:main()
** 函数功能:对ZLG7290进行操作
** 输入函数:无
** 输出函数:无
** 函数说明:在CONFIG.H文件中包含I2CINT.H、ZLG7290.H
*********************************************************************************************************/
int main(void)
{
uint8 disp_buf[8]; /* 发送数据缓冲区 */
uint8 key; /* 定义键值 */
uint8 i;
PINSEL0 = 0x00000000; /* 管脚清零 */
PINSEL1 = 0x00000000;
DelayNS(10);
I2C_Init(30000); /* I2C配置及端口初始化 */
/*
*进行全闪测试
*/
for(i=0; i<8; i++) disp_buf[i] = 0xC8;
ZLG7290_SendBuf(disp_buf,8);
DelayNS(500);
/*
*显示"8 7 6 5 4 3 2 1"
*/
for(i=0; i<8; i++) disp_buf[i] = i+1;
ZLG7290_SendBuf(disp_buf,8);
DelayNS(500);
/*
*显示"LPC2103F" */
disp_buf[7] = 0x14;
disp_buf[6] = 0x16;
disp_buf[5] = 0x0c;
disp_buf[4] = 0x02;
disp_buf[3] = 0x01;
disp_buf[2] = 0x00;
disp_buf[1] = 0x03;
disp_buf[0] = 0x0F;
ZLG7290_SendBuf(disp_buf,8);
/*
*读取按键,设置键值对应的显示位闪烁
*/
while(1) {
DelayNS(1);
key = 0;
IRcvStr(ZLG7290, 0x01, disp_buf, 2);
if(0 == disp_buf[1]) {
key = disp_buf[0];
}
switch(key)
{
case 1: /* 显示命令组合方式 */
case 9:
ZLG7290_SendCmd(0x70, 0x01);
break;
case 2:
case 10:
ZLG7290_SendCmd(0x70, 0x02);
break;
case 3:
case 11:
ZLG7290_SendCmd(0x70, 0x04);
break;
case 4:
case 12:
ZLG7290_SendCmd(0x70, 0x08);
break;
case 5:
case 13:
ZLG7290_SendCmd(0x70, 0x10);
break;
case 6:
case 14:
ZLG7290_SendCmd(0x70, 0x20);
break;
case 7:
case 15:
ZLG7290_SendCmd(0x70, 0x40);
break;
case 8:
case 16:
ZLG7290_SendCmd(0x70, 0x80);
break;
default:
break;
}
}
return(0);
}
/*********************************************************************************************************
** End Of File
*********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -