?? main.c
字號:
/****************************************Copyright (c)**************************************************
** Guangzou ZLG-MCU Development Co.,LTD.
** graduate school
** http://www.zlgmcu.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name: main.c
** Last modified Date: 2004-09-16
** Last Version: 1.0
** Descriptions: The main() function example template
**
**------------------------------------------------------------------------------------------------------
** Created by: zhangmingjie
** Created date: 2007-3-26
** Version: 1.0
** Descriptions: LPC2300系列ARM I2C 操作Zlg7290演示。
**
**------------------------------------------------------------------------------------------------------
** Modified by: yangshiping
** Modified date: 2007-09-03
** Version:
** Descriptions: 對程序的風格以及注釋略作調整,并檢查代碼。
**
** Rechecked by: Litiantian
********************************************************************************************************/
/****************************************************************************
** 文件名:I2CTEST.C
** 功 能 :使用硬件I2C對ZLG7290進行操作,利用中斷方式操作。
** 說 明 :將跳線器JP5短接。
****************************************************************************/
#include "config.h"
#define ZLG7290 0x70 // 定義器件地址
#define Glitter_COM 0x70
/****************************************************************************
** 函數名稱:I2C_Init
** 函數功能:主模式I2C初始化,包括初始化其中斷為向量IRQ中斷。
** 入口參數:fi2c 初始化I2C總線速率,最大值為400K
** 出口參數:無
****************************************************************************/
void I2C_Init(uint32 fi2c)
{
if (fi2c > 400000)
{
fi2c = 400000;
}
PINSEL1 = (PINSEL1 & ~(0xff << 22)) | (0x05 << 22); // 設置I2C控制口有效,P0.27、P0.28
I2SCLH = (Fpclk / fi2c + 1) / 2; // 設置I2C時鐘為fi2c
I2SCLL = (Fpclk / fi2c) / 2;
I2CONCLR = 0x2C;
I2CONSET = 0x40; // 使能主I2C
/* 設置I2C中斷允許 */
VICIntSelect = 0x00; // 所有中斷通道設置為IRQ中斷
VICVectPri9 = 00; // 設I2C中斷最高優先級
VICVectAddr9 = (uint32)IRQ_I2C; // 設置中斷服務程序地址
VICIntEnable = 1 << 0x09; // 使能I2C中斷
}
/****************************************************************************
** 函數名稱:DelayNS
** 函數功能:長軟件延時
** 入口參數:dly 延時參數,值越大,延時越久
** 出口參數:無
****************************************************************************/
void DelayNS(uint32 dly)
{
uint32 i;
for(; dly > 0; dly--)
for(i = 0; i < 5000; i++);
}
/****************************************************************************
** 函數名稱:main
** 函數功能:對ZLG7290進行操作
** 調試說明:1、在CONFIG.H文件中包含I2CINT.H、ZLG7290.H;
** 2、在Flash中進行調試。
****************************************************************************/
int main(void)
{
uint8 disp_buf[8];
uint8 key;
uint8 i;
DelayNS(1000); // 延時,等待7290穩定后再操作I2C總線
I2C_Init(10000); // I2C配置及端口初始化
IRQEnable();
/* 進行全閃測試 */
for (i = 0; i < 8; i++)
{
disp_buf[i] = 0xC8; // 0xC8:顯示8,點亮小數點,閃爍
}
ZLG7290_SendBuf(disp_buf, 8);
DelayNS(9000);
/* 顯示"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(5000);
/* 顯示"LPC2300H" */
disp_buf[7] = 0x14;
disp_buf[6] = 0x16;
disp_buf[5] = 0x0c;
disp_buf[4] = 0x02;
disp_buf[3] = 0x03;
disp_buf[2] = 0x00;
disp_buf[1] = 0x00;
disp_buf[0] = 0x11;
ZLG7290_SendBuf(disp_buf, 8);
/* 讀取按鍵,設置鍵值對應的顯示位閃爍 */
while (1)
{
DelayNS(1);
key = 0;
I2C_ReadNByte(ZLG7290, ONE_BYTE_SUBA, 0x01, disp_buf, 2);
if (0 == disp_buf[1])
{
key = disp_buf[0];
}
switch (key)
{
case 1:
case 9:
ZLG7290_SendCmd(Glitter_COM, 0x01);
break;
case 2:
case 10:
ZLG7290_SendCmd(Glitter_COM, 0x02);
break;
case 3:
case 11:
ZLG7290_SendCmd(Glitter_COM, 0x04);
break;
case 4:
case 12:
ZLG7290_SendCmd(Glitter_COM, 0x08);
break;
case 5:
case 13:
ZLG7290_SendCmd(Glitter_COM, 0x10);
break;
case 6:
case 14:
ZLG7290_SendCmd(Glitter_COM, 0x20);
break;
case 7:
case 15:
ZLG7290_SendCmd(Glitter_COM, 0x40);
break;
case 8:
case 16:
ZLG7290_SendCmd(Glitter_COM, 0x80);
break;
default:
break;
}
}
return (0);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -