📄 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: Chenmingji
** Created date: 2004-09-16
** Version: 1.0
** Descriptions: The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
********************************************************************************************************/
#include "config.h"
#define BEEP (1<<7) /* P0.7为蜂鸣器控制 */
// 声明外部函数
extern void GUI_PutString8_8(uint32 x, uint32 y, char *str);
extern uint8 GUI_PutChar8_8(uint32 x, uint32 y, uint8 ch);
extern uint8 GUI_PutChar24_32(uint32 x, uint32 y, uint8 ch);
extern void DispRGB(void);
extern void CLineDemo(void);
extern void CRectangleDemo(void);
extern void CCircleDemo(void);
// extern void DispXP_Pic(void);
extern void DrawTree( int xStart, int yStart,
double length,
double angle,
int num );
extern void Disp_BKColor(void);
/*
extern void Disp_Pic1(void);
extern void Disp_Pic2(void);
extern void Disp_Pic3(void);
extern void Disp_Pic4(void);
extern void Disp_Pic5(void);
extern void Disp_Pic6(void);
extern void Disp_Pic7(void);
*/
extern void HzDisp(void);
extern void DelayNS(uint32 dly);
extern void I2C_Init(uint32 fi2c);
/****************************************************************************
* 名 称:Beeper()
* 功 能:蜂鸣报警。
* 入口参数:无
* 出口参数:无
****************************************************************************/
void Beeper(uint8 Length)
{
IO0CLR = BEEP;
DelayNS(Length);
IO0SET = BEEP;
DelayNS(2);
}
/****************************************************************************
* 名 称: Alert();
* 功 能: 在TFT6758的最下边显示警告提示信息
* 入口参数: 无
* 出口参数: 无
****************************************************************************/
void Alert(char *str)
{
TCOLOR bak_font_color=disp_color;
TCOLOR bak_bg_color=back_color;
GUI_SetColor(YELLOW, BLACK);
GUI_PutString8_8(50,300,str); //打印提示信息
DelayNS(20);
GUI_SetColor(BLACK,BLACK);
GUI_PutString8_8(50,300,str);
DelayNS(20);
GUI_SetColor(RED,WHITE);
GUI_PutString8_8(50,300,str);
DelayNS(20);
GUI_SetColor(bak_font_color, bak_bg_color);
while(ZLG7290_Key()==0); // 等待用户按下后继续
IO0CLR = BEEP;
DelayNS(50);
IO0SET = BEEP;
DelayNS(2);
}
// LED1--LED4控制宏定义
#define LED_ADJ 20 //28
#define LED_IOCON 0xF0000000
#define LED_OFF() IO2SET=LED_IOCON
#define LED_DISP(dat) LED_OFF(); IO2CLR=((dat)<<LED_ADJ)
// 定义LED显示数据
uint8 const LED_DISP_TAB[42] =
{ 0x0F, 0x00, 0x0F, 0x00, 0x0F, 0x00, // 全闪
0x0F, 0x00, 0x0F, 0x00, 0x0F, 0x00,
0x00, 0x01, 0x03, 0x07, 0x0F, 0x07, // 向右增加
0x03, 0x01, 0x00,
0x05, 0x0A, 0x05, 0x0A, 0x05, 0x0A, // 向左移动
0x05, 0x0A, 0x05, 0x0A, 0x05, 0x0A,
0x00, 0x08, 0x0C, 0x0E, 0x0F, 0x0E, // 向右增加
0x0C, 0x08, 0x00
};
const uint32 DISP_TAB[17] = {
0x0fffffff,0x1fffffff, 0x2fffffff, 0x3fffffff,
0x4fffffff,0x5fffffff, 0x6fffffff, 0x7fffffff,
0x8fffffff,0x9fffffff, 0xafffffff, 0xbfffffff,
0xcfffffff,0xdfffffff, 0xefffffff, 0xffffffff,0
};
static uint8 led_no = 0; // LED显示数据计数器(LED_DISP_TAB[led_no])
/****************************************************************************
* 名称:IRQ_Time0()
* 功能:定时器0中断服务程序,取反LEDCON控制口。
* 入口参数:无
* 出口参数:无
****************************************************************************/
void __irq IRQ_Time0(void)
{ // 设置LED显示数据计数器
led_no++;
if(led_no>=42)
{ led_no = 0;
}
// LED_DISP(LED_DISP_TAB[led_no]);
T0IR = 0x02; // 清除中断标志
VICVectAddr = 0x00; // 通知VIC中断处理结束
}
/****************************************************************************
* 名称:Time0Init()
* 功能:初始化定时器0,定时时间为0.3S,并打开中断。
* 入口参数:无
* 出口参数:无
****************************************************************************/
void Time0Init(void)
{
T0PR = 99; // 设置定时器0分频为100分频,得110592Hz
T0MCR = 0x03<<3; // 匹配通道1匹配中断并复位T0TC
T0MR1 = 110592/3; // 设置MR1比较值(0.3S定时值)
T0TCR = 0x03; // 启动并复位T0TC
T0TCR = 0x01;
/* 设置定时器0中断IRQ */
VICIntSelect = 0x00; // 所有中断通道设置为IRQ中断
VICVectCntl0 = 0x24; // 定时器0中断通道分配最高优先级(向量控制器0)
VICVectAddr0 = (uint32)IRQ_Time0; // 设置中断服务程序地址向量
// VICIntEnable = 0x00000010; // 使能定时器0中断
}
// 主程序。控制LCD显示图片、汉字,控制LED显示流水灯。
int main (void)
{
char hlju[]="hlju2005!",Key_Value=0,Pos_X=100,Pos_Y=100;
uint8 str[]="Window1",i=0;
char msg[]="Press any key to continue!";
WINDOWS win;//={100,100,100,100,(uint8)"Win1",(uint8)"State"};
win.x=100;
win.y=100;
win.with=100;
win.hight=100;
win.title=str;
win.state=str;
PINSEL0 = 0x00000000;
PINSEL1 = 0x00000000;
IO0DIR = BEEP; // 设置蜂鸣器的控制口为输出
IO2DIR = LED_IOCON; // 设置LED1--LED4的控制口为输出
LED_OFF();
for(i=0; i<8; i++)
{
IO2CLR = DISP_TAB[i&0x00000007]; // 输出LED显示数据
DelayNS(10); // 延时
IO2SET = 0xffffffff;
}
srand(3721); // 初始化随机总机
//Time0Init();
I2C_Init(100000); // I2C初始化
GUI_Initialize();
while(1)
{
GUI_SetColor(YELLOW, BLACK);
GUI_PutString8_8(10,300,"Press S15 to continue!");
GUI_PutString8_8(10,20,"Use S1,S2,S3,S6 to move the char A");
while((Key_Value=ZLG7290_Key())!=0x0F) // 当S15按下后才退出键盘测试
{
GUI_PutChar8_8(Pos_X,Pos_Y,'A');
if(Key_Value!=0)
{
GUI_PutChar8_8(Pos_X,Pos_Y,' ');
IO2SET = 0xffffffff;
IO2CLR =DISP_TAB[Key_Value]; // 输出LED显示数据
switch (Key_Value)
{
case 1: {
Pos_X--;
break;
}
case 2: {
Pos_Y++;
break;
}
case 3: {
Pos_X++;
break;
}
case 6: {
Pos_Y--;
break;
}
default: break;
}
GUI_PutChar8_8(Pos_X,Pos_Y,'A');
}
}
Beeper(2);
GUI_ClearSCR();
CCircleDemo();
Alert(msg);
GUI_ClearSCR();
GUI_SetColor(YELLOW, BLACK);
GUI_PutString(100,100,hlju);
GUI_PutString8_8(100, 120, hlju);
// GUI_PutChar24_32(100,150,5); // this function doesn't work!
Alert(msg);
GUI_WindowsDraw(&win);
Alert(msg);
// 控制蜂鸣器响
Beeper(15);
/*
// 画图操作演示
CLineDemo();
GUI_ClearSCR();
CRectangleDemo();
GUI_ClearSCR();
*/
// DispXP_Pic(); // 显示背景图片
DrawTree(120,260, 30, 1.67, 9);
Alert("Press Any Key to continue!");
GUI_ClearSCR();
/*
// 显示RGB三色
DispRGB();
DelayNS(200); // 延时
*/
// 图片显示演示
/*
Disp_Pic1();
DelayNS(300);
Disp_Pic2();
DelayNS(300);
Disp_Pic3();
DelayNS(300);
Disp_Pic4();
DelayNS(300);
// 广告图片显示
Disp_Pic5();
DelayNS(300);
Disp_Pic6();
DelayNS(300);
Disp_Pic7();
DelayNS(300);
GUI_ClearSCR();
*/
// 显示" 广州周立功
// 单片机
// 发展有限公司 "
HzDisp();
DelayNS(200); // 延时
GUI_ClearSCR();
}
return(0);
}
/*********************************************************************************************************
** End Of File
********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -