📄 task.c
字号:
#include "44b.h"
#include "def.h"
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#define HT_DELAY (10)
#define LED_DELAY (30000)
#define SEG_DELAY (30000)
#define UART_DELAY (30000)
#define UART_BAUD (115200)
#define MCLK (60000000)
#define rSEGDISP (*(volatile unsigned *)0x04000000)
static int whichUart = 0;
void Uart_Select(int ch);
void Uart_Sendch(char data);
void Uart_SendData(char data);
void Uart_SendString1(char *pt);
void Uart_Printf1(char *fmt,...);
int Uart_Flush(void) ;
void Uart_Init1(long clk,long baud);
void Sys_Init(void)
{
rSYSCFG = CACHECFG;
//rNCACHBE0 = 0XC0002000;
rPCONB = 0x1cf;
rPDATB = 0xffff;
/* PORTE */
rPCONE = 0x5568;
rPDATE = 0xd0;
rPUPE = 0x6;
Uart_Select(0);
Uart_Init1(MCLK,UART_BAUD);
}
void Led_Display1(U32 LedStatus)
{
rPDATB = LedStatus;
}
void Seg_Display(U32 SegStatus)
{
rSEGDISP = SegStatus;
}
void Delay1(int time)
{
int counter=time*400;
while(counter--);
}
void Led_Test(void)
{
Led_Display1(0x0);
Delay1(LED_DELAY);
Led_Display1(0x7df);
Delay1(LED_DELAY);
Led_Display1(0x7ef);
Delay1(LED_DELAY);
Led_Display1(0x3ff);
Delay1(LED_DELAY);
Led_Display1(0x5ff);
Delay1(LED_DELAY);
Led_Display1(0xffff);
Delay1(LED_DELAY);
}
void Seg_Test(void)
{
/* Use the high 8 bit */
Seg_Display(0x12000000);
Delay1(SEG_DELAY);
Seg_Display(0x9f000000);
Delay1(SEG_DELAY);
Seg_Display(0x31000000);
Delay1(SEG_DELAY);
Seg_Display(0x15000000);
Delay1(SEG_DELAY);
Seg_Display(0x9c000000);
Delay1(SEG_DELAY);
Seg_Display(0x54000000);
Delay1(SEG_DELAY);
Seg_Display(0x50000000);
Delay1(SEG_DELAY);
Seg_Display(0x1f000000);
Delay1(SEG_DELAY);
Seg_Display(0x10000000);
Delay1(SEG_DELAY);
Seg_Display(0x14000000);
Delay1(SEG_DELAY);
Seg_Display(0xff000000);
}
void Uart_Test(void)
{
Uart_Sendch(0x0d);
Uart_Sendch(0x0a);
Uart_Printf1("@ Q__Q \n" );
Uart_Sendch(0x0d);
Uart_Sendch(0x0a);
Delay1(UART_DELAY);
Uart_Printf1("@ /____\\ \n" );
Uart_Sendch(0x0d);
Uart_Sendch(0x0a);
Delay1(UART_DELAY);
Uart_Printf1("@ \\____/ \n" );
Uart_Sendch(0x0d);
Uart_Sendch(0x0a);
Delay1(UART_DELAY);
Uart_Printf1("@ /\\/\\ \n" );
Uart_Sendch(0x0d);
Uart_Sendch(0x0a);
Delay1(UART_DELAY);
Uart_Printf1("@ __(\\\\//)__ \n" );
Uart_Sendch(0x0d);
Uart_Sendch(0x0a);
Delay1(UART_DELAY);
Uart_Printf1("@ >__/ww\\__< \n" );
Delay1(UART_DELAY);
Uart_Sendch(0x0d);
Uart_Sendch(0x0a);
Uart_Printf1("@\n" );
}
void Uart_Init1(long clk,long baud)
{
/* FIFO disable, MODEM disable */
rUFCON0 = 0x0;
rUFCON1 = 0x0;
rUMCON0 = 0x0;
rUMCON1 = 0x0;
/* Normal,No parity,1 stop,8 bit */
rULCON0 = 0x3;
rUCON0 = 0x205;
rUBRDIV0 = (int)(clk / 16 / baud + 0.5) - 1;
rULCON1 = 0x3;
rUCON1 = 0x205;
rUBRDIV1 = (int)(clk / 16 / baud + 0.5) - 1;
}
/******************** Uart_Select ************************/
void Uart_Select(int ch)
{
whichUart = ch;
}
/******************** Uart_SendByte **********************/
void Uart_Sendch(char data)
{
if(whichUart==0)
{
if(data=='\n')
{
while(!(rUTRSTAT0 & 0x2));
/* For the slow response of HT */
Delay1(HT_DELAY);
WrUTXH0('\r');
}
while(!(rUTRSTAT0 & 0x2));
Delay1(HT_DELAY);
WrUTXH0(data);
}
else
{
if(data=='\n')
{
while(!(rUTRSTAT1 & 0x2));
Delay1(HT_DELAY);
rUTXH1='\r';
}
while(!(rUTRSTAT1 & 0x2));
Delay1(HT_DELAY);
rUTXH1=data;
}
}
/******************** Uart_SendByte **********************/
void Uart_SendData(char data)
{
if(whichUart==0)
{
while(!(rUTRSTAT0 & 0x2));
WrUTXH0(data);
}
else
{
while(!(rUTRSTAT1 & 0x2));
rUTXH1=data;
}
}
/******************** Uart_SendString **********************/
void Uart_SendString1(char *pt)
{
while(*pt)
Uart_Sendch(*pt++);
}
/******************** Uart_Printf **********************/
void Uart_Printf1(char *fmt,...)
{
va_list ap;
char string[256];
va_start(ap,fmt);
vsprintf(string,fmt,ap);
Uart_SendString1(string);
va_end(ap);
}
/******************** Uart_Flush **********************/
int Uart_Flush(void)
{
char temp;
if(whichUart == 0)
{
if(rUTRSTAT0 & 0x1)
{
temp = RdURXH0();
return 1;
}
else
return 0;
}
else
{
if(rUTRSTAT1 & 0x1)
{
temp = RdURXH1();
return 1;
}
else
return 0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -