📄 vguart.c
字号:
#include "VGSDKpv.h"
/*******************************************************/
/*******************************************************/
#ifdef __vgSDK_SE3208__
/*******************************************************/
/*******************************************************/
////////////////////////////////////////////////////////////////
/// 2001.2.13. Virgine Start Program ///
/// Program by EungSang.LEE ///
////////////////////////////////////////////////////////////////
typedef unsigned short word;
typedef unsigned char byte;
byte *regb=(byte *) 0x01800000;
#define regw *(word*)®b
#define regl *(int *)®b
void UartConfig0(void)
{
#ifdef _DEBUG
regb[0x1000]=0x11; //uart 0=uclk,n,8,1
regw[0x1010]=0x0002; //1843200/16/(2+1)=38400bps
#endif
}
void UartConfig1(void)
{
#ifdef _DEBUG
regb[0x1020]=0x11; // uclk,8bit data
regw[0x1030]=0x0002; // 3579500/((16*(5+1)) = 38400bps
#endif
}
#ifdef _DEBUG
short RxFul0(void)
{
short sh;
sh=regw[0x1004];
if(sh&0x0010) return 1;
else return 0;
}
short RxFul1(void)
{
short sh;
sh=regw[0x1024];
if(sh&0x0010) return 1;
else return 0;
}
char Rx0(void)
{
return regb[0x100c];
}
char Rx1(void)
{
return regb[0x102c];
}
short TxEmpty0(void)
{
char ch;
ch=regb[0x1004];
if(ch&0x20) return 0;
else return 1;
}
short TxEmpty1(void)
{
char ch;
ch=regb[0x1024];
if(ch&0x20) return 0;
else return 1;
}
void Tx0(char ch)
{
while(!TxEmpty0());
regb[0x1008]=ch;
}
void Tx1(char ch)
{
while(!TxEmpty1());
regb[0x1028]=ch;
}
void SendString_vgUart( char* pt )
{
while( *pt )
{
if( *pt == '\n' ) Tx1( '\r' );
Tx1( *pt++ );
}
}
#endif
/*******************************************************/
/*******************************************************/
#else //defined(__vgSDK_ARM7__) //for #ifdef __vgSDK_SE3208__
/*******************************************************/
/*******************************************************/
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include "vguart.h"
static int whichUart = 1;
void vgdelay( U32 ch )
{
U32 i, j;
for(i=0; i<ch; i++)
{
for(j=0; j<0xff; j++) {}
}
}
// use UART0
void Preset_vgUart_Num0( void )
{
PCONF = 0x124800; // Set PCONF( nCTS0, RxD0, TxD0, nRTS0)
}
// use UART1
void Preset_vgUart_Num1( void )
{
PCONF = 0x124800; // Set PCONF( nCTS1, RxD1, TxD1, nRTS1 )
}
void Init_vgUart( U8 mode, U8 databit, U8 stopbit,
U8 parity, U32 mclk, U16 baudrate )
{
U16 i;
U8 ch0, ch1;
if( mclk==0 ) mclk = (U32)vgUART_MCLK;
UFCON0 = 0x0; // FIFO disable
UFCON1 = 0x0;
/* UART0 */
ch0 = (U8)(mode | databit | stopbit | parity);
ULCON0 = ch0;
UCON0 = 0x245; // tx level, rx evge, disable timeout int, enable rx error int, normal, normal, int or polling
UBRDIV0 = ( (U16)(mclk / (baudrate * 16) + 0.5) - 1 );
/* UART1 */
ch1 = (U8)(mode | databit | stopbit | parity);
ULCON1 = ch1;
UCON1 = 0x245; // tx level, rx evge, disable timeout int, enable rx error int, normal, normal, int or polling
UBRDIV1 = ( (U16)(mclk / (baudrate * 16) + 0.5) - 1 );
for(i=0; i<100; i++);
}
void Select_vgUart( U8 uartnumber )
{
whichUart = uartnumber; // 0 or 1
}
void vgUart_TxEmpty( void )
{
if( whichUart==0 )
while( !(UTRSTAT0 & 0x02) ); // wait until tx0 FIFO/buffer is empty
else
while( !(UTRSTAT1 & 0x02) ); // wait until tx1 FIFO/buffer is empty
}
U8 Getch_vgUart( void )
{
if( whichUart==0 )
{
while( !(UTRSTAT0 & 0x01) );
return URXH0;
}
else
{
while( !(UTRSTAT1 & 0x01) );
return URXH1;
}
}
void SendByte_vgUart( U8 data )
{
if( whichUart==0 )
{
if( data=='\n' )
{
while( !(UTRSTAT0 & 0x2) ); // wait until tx0 FIFO/buffer is empty
vgdelay( 10 ); //because the slow response of hyper_terminal
UTXH0 = '\r';
}
while( !(UTRSTAT0 & 0x2) ); //Wait until THR is empty.
vgdelay( 10 );
UTXH0 = data;
}
else
{
if( data=='\n' )
{
while( !(UTRSTAT1 & 0x2) ); // wait until tx1 FIFO/buffer is empty
vgdelay( 10 ); //because the slow response of hyper_terminal
UTXH1 = '\r';
}
while( !(UTRSTAT1 & 0x2) ); //Wait until THR is empty.
vgdelay( 10 );
UTXH1 = data;
}
}
void SendString_vgUart( char* pt )
{
while( *pt )SendByte_vgUart( *pt++ );
}
/*******************************************************/
/*******************************************************/
#endif //for #ifdef __vgSDK_SE3208__
/*******************************************************/
/*******************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -