📄 myblinky.c
字号:
/*
* 说明:Uart工作正常,P4.2口控制LED显示
*
*
*/
#include <aduc7026.h>
#define LED2 (0x01 << 2)
#define LEDON (GP4CLR |= (LED2 << 16))
#define LEDOFF (GP4SET |= (LED2 << 16))
#define Fcore 41780000L
#define Baut 19200
void Delay(int time)
{
int i;
while(time > 0){
time--;
i = 255;
while(i > 0){
i--;
}
}
}
void SysInit()
{
PLLKEY1 = 0xAA;
PLLCON = 0x01; //PLL + 32kHz oscillator – default configuration
PLLKEY2 = 0x55;
POWKEY1 = 0x01;
POWCON = 0x00; //the clock configured as 45.088M
POWKEY2 = 0xF4;
}
void UartInit()
{
GP1CON = 0x11; //SIN SOUT LINK TO P1.0,P1.1
COMCON0 = 0x83; //SETTING TO ACCESS DIV0 AND DIV1
COMDIV0 = 0x44; //baute rate at 19200 bps
COMDIV1 = 0x0;
COMCON0 = 0X03; //SET TO OUT DIV0 AND DIV1
}
void SendByte(unsigned char Bdata)
{
while(!(COMSTA0 & 0x40));
COMTX = Bdata;
}
void PrintStr(unsigned char *p)
{
int i = 0;
while( p[i] != 0){
SendByte(p[i]);
i++;
}
SendByte(0x0D);
SendByte(0x0A);
}
/*
* 等字宽输出数字 如00011 01234
*/
/*void SendNum(int num)
{
SendByte(num / 10000 + 0x30);
num = num % 10000;
SendByte(num / 1000 + 0x30);
num = num % 1000;
SendByte(num / 100 + 0x30);
num = num % 100;
SendByte(num / 10 + 0x30);
SendByte(num % 10 + 0x30);
}*/
/*
* 串口终端输出数字
* 数大小为16位 《= 99999
*/
void SendNum(int num)
{
if(num >= 10){
if(num >=100){
if(num >= 1000){
if(num>= 10000){
SendByte(num / 10000 + 0x30);
num = num % 10000;
}
SendByte(num / 1000 + 0x30);
num = num % 1000;
}
SendByte(num / 100 + 0x30);
num = num % 100;
}
SendByte(num / 10 + 0x30);
}
SendByte(num % 10 + 0x30);
}
int main(void)
{
GP4DAT |= (LED2 << 24); //set p4.2 as output
SysInit();
UartInit();
PrintStr("hello begin!");
PrintStr("line one\n");
SendNum(0x112);
SendNum(11);
while(1){
LEDON;
Delay(2000);
LEDOFF;
Delay(2000);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -