44blib.c

来自「开发环境:ADS 1.2 目标平台:ARM:S3C44B0 显示屏:tft」· C语言 代码 · 共 213 行

C
213
字号

#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>

#include "44b.h"
#include "44blib.h"
#include "def.h"
#include "option.h"

//--------------------------------SYSTEM---------------------------------//
static int delayLoopCount=400;

void Delay(int time)
// 100us resolution.//
{
	int i;
	for(;time>0;time--)
		for(i=0;i<delayLoopCount;i++);
	//while((rPDATC&0x01)==0x00);
}


void SoftDelay(int ms)//64M, delay about 1ms
{
	int i,j,k;
	for(i=0;i<ms;i++)
	{
		for(j=0;j<256;j++);
		for(k=0;k<256;k++);
	}
}

//------------------------PORTS------------------------------//
void Port_Init(void)
{
    rPCONA = 0x3ff;	

    rPDATB = 0x7ff;
    rPCONB = 0x7ff;	
    
    rPDATC = 0xffff;	
    rPCONC = 0x55555555;	
    rPUPC  = 0x0000;

    rPDATD= 0xff;
    rPCOND= 0x5555;	
    rPUPD = 0x0;	
    
    rPDATE  = 0xff;
    rPCONE  = 0x05428;	
    rPUPE   = 0x19;		

    
    rPDATF = 0x1ff;
    rPCONF = 0x000120;	
    rPUPF  = 0x1ff;	
    	
    rPDATG = 0xff;
    rPCONG = 0x0015; 	
    rPUPG  = 0x07;		
    
    rSPUCR = 0x7;         //D15-D0 pull-up disable
    rEXTINT= 0x0;         //均为低电平触发

}
/************************* UART ****************************/
void Uart_Init(void)
{
    int i;

    rUFCON0=0x0;     //FIFO disable
    rUFCON1=0x0;
    rUMCON0=0x0;
    rUMCON1=0x0;

    rULCON0=0x3;     //Normal,No parity,1 stop,8 bit
    rUCON0=0x245;    //rx=edge,tx=level,disable timeout int.,enable rx error int.,normal,interrupt or polling
    rUBRDIV0=( (int)(MCLK/16./115200 + 0.5) -1 );

    for(i=0;i<100;i++);
}


void Uart_TxEmpty(int ch)
{
		while(!(rUTRSTAT0 & 0x4)); //wait until tx shifter is empty.
}


char Uart_Getch(void)
{
		while(!(rUTRSTAT0 & 0x1)); //Receive data read
		return RdURXH0();
}


char Uart_GetKey(void)
{
	if(rUTRSTAT0 & 0x1)    //Receive data ready
   	    return RdURXH0();
	else
	    return 0xff;
}


void Uart_GetString(char *string)
{
    char *string2=string;
    char c;
    while((c=Uart_Getch())!='\r')
    {
		if(c=='\b')
		{
		    if(	(int)string2 < (int)string )
		    {
				Uart_SendString("\b \b");
				string--;
		    }
		}
		else 
		{
		    *string++=c;
		    Uart_SendByte(c);
		}
    }
    *string='\0';
    Uart_SendByte('\n');
}


void Uart_SendByte(int data)
{
	if(data=='\n')
	{
	    while(!(rUTRSTAT0 & 0x2));
	    Delay(10);	//because the slow response of hyper_terminal 
	    WrUTXH0('\r');
	}
	while(!(rUTRSTAT0 & 0x2)); //Wait until THR is empty.
	Delay(10);
	WrUTXH0(data);
}		


void Uart_SendString(char *pt)
{
    while(*pt)
	Uart_SendByte(*pt++);
}


int Uart_RxReady(void)
{
	return (rUTRSTAT0 & 0x1);	//Receive data ready
}



/************************* General Library **********************/

int _atoi_(char *str)
{
    int n=0;
    char c=1;

    while((c=*str++)&&(c>=0x30)&&(c<=0x39))
            n = n*10 + c-'0';
    return(n);
}

void itoa(U32 t)
{
    unsigned char a,i;
    char ch[11];

    a=t/1000000000;
    ch[10]=a+0x30;
    t=t%1000000000;
    a=t/100000000;
    ch[9]=a+0x30;
    t=t%100000000;
    a=t/10000000;
    ch[8]=a+0x30;
    t=t%10000000;
    a=t/1000000;
    ch[7]=a+0x30;
    t=t%1000000;
    a=t/100000;
    ch[6]=a+0x30;
    t=t%100000;
    a=t/10000;
    ch[5]=a+0x30;
    t=t%10000;
    a=t/1000;
    ch[4]=a+0x30;
    t=t%1000;
    a=t/100;
    ch[3]=a+0x30;
    t=t%100;
    a=t/10;
    ch[2]=a+0x30;
    t=t%10;
    a=t;
    ch[1]=a+0x30;
    ch[0]='\0';
    for(i=4;i>0;i--)
        Uart_SendByte(ch[i]);
    Uart_SendString("    ");
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?