⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 public_function.c

📁 s3c44b0红外解码。源码使用SOURCE INSIGHT打开 用ADS1.2编译。
💻 C
字号:
#include ".\inc\def.h"
#include ".\inc\option.h"
#include ".\inc\44b.h"
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
/*******************************************************************
void Port_Init(void);
void Uart_Init(int mclk,int baud);
void Uart_Select(int ch);
void Delay(int time);
void Isr_Init(void);
char Uart_Getch(void);
void Uart_SendString(char *pt);
void Uart_Printf(char *fmt,...);
void uart_IR_flash(int flash_time);
void read_write_flash(void);
#define LOOP 1000
******************************************************************************/
//void Uart_SendByte(int data);
static int delayLoopCount=400;
static int whichUart=0;

void Isr_Init(void)
{
    U32 i;
    
    for(i=_RAM_STARTADDRESS;i<(_RAM_STARTADDRESS+0x20);i+=4)
    {
	  *((volatile unsigned *)i)=0xEA000000+0x1FFE;
    }

    //rINTCON=0x1;	  // Vectored Int. IRQ enable,FIQ disable    
    rINTCON=0x5;	  // Non-vectored,IRQ enable,FIQ disable    

    rINTMOD=0x0;	  // All=IRQ mode
    rINTMSK|=BIT_GLOBAL|BIT_EINT4567;	  // All interrupt is masked.
}


void Port_Init(void)
{   
    //PORT C GROUP
	
	rPDATC = 0x0000;
	rPCONC = 0xfff5ff55;
	rPUPC=0x00;
    
   	//PORT E GROUP
	rPCONE=0x05969;//0x6552a;//0x2B;	
	  
 }
 
 void Uart_Init(int mclk,int baud)
{
    int i;
    if(mclk==0)
	mclk=MCLK;
    rUFCON0=0x0;     //FIFO disable
    rUFCON1=0x0;
    rUMCON0=0x0;
    rUMCON1=0x0;
//UART0
    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./baud + 0.5) -1 );
//UART1
    rULCON1=0x3;
    rUCON1=0x245;
    rUBRDIV1=( (int)(mclk/16./baud + 0.5) -1 );
    for(i=0;i<100;i++);
}

void Uart_Select(int ch)
{
    whichUart=ch;
}


void Delay(int time)//以100us为单位的延时程序
{
    int i,adjust=0;
    if(time==0)
    {
	time=200;
	adjust=1;
	delayLoopCount=400;
	rWTCON=((MCLK/1000000-1)<<8)|(2<<3);  // 1M/64,Watch-dog,nRESET,interrupt disable
	rWTDAT=0xffff;
	rWTCNT=0xffff;	 
	rWTCON=((MCLK/1000000-1)<<8)|(2<<3)|(1<<5); // 1M/64,Watch-dog enable,nRESET,interrupt disable 
    }
    for(;time>0;time--)
	for(i=0;i<delayLoopCount;i++);
    if(adjust==1)
    {
	rWTCON=((MCLK/1000000-1)<<8)|(2<<3);
	i=0xffff-rWTCNT;                 //  1count/16us?
	delayLoopCount=8000000/(i*64);	//400*100/(i*64/200)   
    }
}

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


//if you don't use vsprintf(), the code size is reduced very much.

void Uart_Printf(char *fmt,...)
{
    va_list ap;
    char string[256];

    va_start(ap,fmt);
    vsprintf(string,fmt,ap);
    Uart_SendString(string);
    va_end(ap);
}

void Uart_SendByte(int data)
{
    if(whichUart==0)
    {
	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);
    }
    else
    {
	if(data=='\n')
	{
    	while(!(rUTRSTAT1 & 0x2));
	    Delay(10);	//because the slow response of hyper_terminal 
	    rUTXH1='\r';
	}
	while(!(rUTRSTAT1 & 0x2));  //Wait until THR is empty.
	Delay(10);
	rUTXH1=data;
    }	
}


void uart_IR_flash(int flash_time)
{  int i=0,ir_time=3000;//改变ir_time可以改变led闪烁的频率
   int T=500;//T 改变发光亮度
   Uart_Select(1);
  while(flash_time)
    {while(T!=0)
	{Uart_Printf("%d",i);
	  T--;
    }
	  Delay(ir_time); 
	  flash_time--;
   	}
}


char Uart_Getch(void)
{
    if(whichUart==0)
    {	    
	while(!(rUTRSTAT0 & 0x1)); //Receive data read
	return RdURXH0();
    }
    else
    {
	while(!(rUTRSTAT1 & 0x1)); //Receive data ready
	return	rURXH1;
    }
}


⌨️ 快捷键说明

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