📄 utils.c
字号:
#include <windows.h>
#include "s2450addr.h"
#include "option.h"
#include "utils.h"
//***************************[ PORTS ]****************************************************
void Port_Init(void)
{
}
void Led_Display(int data)
{
// Active is low.(LED On)
// GPF7 GPF6 GPF5 GPF4
// nLED_8 nLED4 nLED_2 nLED_1
//
rGPFDAT = (rGPFDAT & ~(0xf<<4)) | ((data & 0xf)<<4);
}
// Do-nothing delay loop.
//
void Delay(void)
{
volatile int i;
for(i=0 ; i < 1000 ; i++)
{
}
}
//***************************[ UART ]******************************
void Uart_Init(void)
{
int i;
rGPHCON = rGPHCON & ~((3 << 4)|(3 << 6));
rGPHCON = rGPHCON | ((2 << 4)|(2 << 6));
// Disable pull-up on TXD1 and RXD1.
//
#if (BSP_TYPE == BSP_SMDK2443)
#ifdef EVT1
rGPHUDP = rGPHUDP | ((1 << 4)|(1 << 6));
#else
rGPHUDP = rGPHUDP | ((2 << 4)|(2 << 6));
#endif
#elif (BSP_TYPE == BSP_SMDK2450)
rGPHUDP = rGPHUDP | ((1 << 4)|(1 << 6));
#endif
rUFCON1 = 0x0; // FIFO disable
rUMCON1 = 0x0; // AFC disable
rULCON1 = 0x3; // Normal,No parity,1 stop,8 bits
rUCON1 = 0x005;
rUBRDIV1=( (int)(PCLK/16./115200) -1 );
for(i=0;i<100;i++);
}
//=====================================================================
void Uart_SendByte(int data)
{
if(data=='\n')
{
while(!(rUTRSTAT1 & 0x2));
Delay(); //because the slow response of hyper_terminal
WrUTXH1('\r');
}
while(!(rUTRSTAT1 & 0x2)); //Wait until THR is empty.
Delay();
WrUTXH1(data);
}
//====================================================================
void Uart_SendString(char *pt)
{
while(*pt)
Uart_SendByte(*pt++);
}
//====================================================================
void Uart_SendDWORD(DWORD d, BOOL cr)
{
Uart_SendString("0x");
Uart_SendString(hex2char((d & 0xf0000000) >> 28));
Uart_SendString(hex2char((d & 0x0f000000) >> 24));
Uart_SendString(hex2char((d & 0x00f00000) >> 20));
Uart_SendString(hex2char((d & 0x000f0000) >> 16));
Uart_SendString(hex2char((d & 0x0000f000) >> 12));
Uart_SendString(hex2char((d & 0x00000f00) >> 8));
Uart_SendString(hex2char((d & 0x000000f0) >> 4));
Uart_SendString(hex2char((d & 0x0000000f) >> 0));
if (cr)
Uart_SendString("\n");
}
void Uart_SendBYTE(BYTE d, BOOL cr)
{
//Uart_SendString("0x");
Uart_SendString(hex2char((d & 0x000000f0) >> 4));
Uart_SendString(hex2char((d & 0x0000000f) >> 0));
Uart_SendString(" ");
if (cr)
Uart_SendString("\n");
}
//====================================================================
char *hex2char(unsigned int val)
{
static char str[2];
str[1]='\0';
if(val<=9)
str[0]='0'+val;
else
str[0]=('a'+val-10);
return str;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -