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

📄 main.c

📁 led,key,i2c,uart,adc,rtc,wdt测SHI 文件代码
💻 C
字号:
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "..\inc\option.h"
#include "..\inc\def.h"
#include "..\inc\44b.h"
#include "..\inc\44blib.h"
#include "..\inc\iic.h"
#include "..\inc\pwm.h"
#include "..\inc\adc.h"
#include "..\inc\wdt.h"
#include "..\inc\rtc.h"

#define BMON_ADDRESS 0x0c7F0000

void __irq Eint4567Isr(void);
void __irq Uart0_RxInt(void);
void Isr_Init(void);
void HaltReset(void);
void HaltUndef(void);
void HaltSwi(void);
void HaltPabort(void);      
void HaltDabort(void);

void (*restart)(void)=(void (*)(void))0x0;

volatile char which_int=0;
volatile char aa=0xff;
//########################
//TEST LED
//TEST UART 0
//TEST KEY,INTERRUPT MODE
//IIC
//pwm beep
//#######################
void Main(void)
{	
	
	Port_Init();
	Beep();
	Led_Display(7);
	Delay(10000);
	Led_Display(0);
	Isr_Init();
	Uart_Init(0,115200);
	Uart_Select(0); //Select UART0
    /*******************************/
    /*          Banner             */
    /*******************************/
	Uart_Printf("\n******************************************************");
	Uart_Printf("\n         #           #########        ###       ###");
	Uart_Printf("\n        ###          ##       ##      ####     ####");
	Uart_Printf("\n       ## ##         ##       ###     ## ##   ## ##");
	Uart_Printf("\n      ##   ##        ##       ##      ##  ## ##  ##");
	Uart_Printf("\n     #########       #########        ##   ###   ##");
	Uart_Printf("\n    ##       ##      ##     ##        ##    #    ##");
	Uart_Printf("\n   ##         ##     ##      ##       ##         ##");
	Uart_Printf("\n  ####       ####   ####     ####    ####       ####");
    Uart_Printf("\n******************************************************");
    Uart_Printf("\n start test uart0\n");
    Uart_Printf("\nWelcome to www.efw520.com!");
	Uart_Printf("\nPlease Press 'y' ->all led on");  
	Uart_Printf("\nPlease Press 'n' ->all led off");  
    Uart_Printf("\nPlease Press '0' ->led0 on");    
    Uart_Printf("\nPlease Press '1' ->led1 on"); 
    Uart_Printf("\nPlease Press '2' ->led2 on");
    Uart_Printf("\nPlease Press 'i' ->test iic"); 
    Uart_Printf("\nPlease Press 'b' ->test beep");
    Uart_Printf("\nPlease Press 'p' ->pwm test"); 
    Uart_Printf("\nPlease Press 'a' ->adc test");
    Uart_Printf("\nPlease Press 't' ->rtc test");
    Uart_Printf("\nPlease Press 'w' ->watch dog test"); 
    Uart_Printf("\nPlease Press 'r' ->restart");
	while(1)
	{
		if (which_int)
		{
			switch(which_int)					//根据中断源,从串口发送对应字符,并点亮led
			{
				case 1:		Uart_Printf("\nkey 1 pressed");  break;
				case 2:		Uart_Printf("\nkey 2 pressed");  break;
				case 4:		Uart_Printf("\nkey 3 pressed");  break;
				case 8:		Uart_Printf("\nkey 4 pressed");  break;
				default:	Uart_Printf("\nunknow key!");
			}
			which_int=0;
		}
		
		switch(aa)
	    {
	    	case '0':
	    	    Uart_Printf("\nYou Pressed '0'");
	    	    Led_Display(1);
	    	    break;
	    	case '1':
	    	    Uart_Printf("\nYou Pressed '1'");
	    	    Led_Display(2);
	    	    break;
	    	case '2':
	            Uart_Printf("\nYou Pressed '2'");
	            Led_Display(4);
	    	    break;
	    	case 'n':
	    	case 'N':
	    		Uart_Printf("\nYou Pressed 'n'");
	    		Led_Display(0);
	    	    break;
	    	case 'y':
	    	case 'Y':
	    		Uart_Printf("\nYou Pressed 'y'");
	    		Led_Display(7);
	    	    break;
	    	case 'b':
	    	case 'B':
	    		Uart_Printf("\nYou Pressed 'b'");
	    		Beep();;
	    	    break;
	    	case 'p':
	    	case 'P':
	    		Uart_Printf("\nYou Pressed 'p'");
	    		Test_TimerInt();
	    	    break;		    	    	
	    	case 'i':
	    	case 'I':
	    		Uart_Printf("\nYou Pressed 'i'");
	    		Test_Iic();
	    	    break;
	    	case 'a':
	    	case 'A':
	    		Uart_Printf("\nYou Pressed 'a'");
	    		Test_Adc();
	    	    break;
	    	case 't':
	    	case 'T':
	    		Uart_Printf("\nYou Pressed 't'");
	    		while (Test_Rtc_Alarm()!=1);
	    		Uart_Printf("\ntest rtc tick 't'");
	    		Test_Rtc_Tick();
	    		Display_Rtc();
	    	    break;	    	    
	    	case 'w':
	    	case 'W':
	    		Uart_Printf("\nYou Pressed 'w'");
	    		Test_WDTimer();
	    	    break;	  	    	    	   	    	    	    	    
			case 'r':
			case 'R':
	    		Uart_Printf("\nYou Pressed 'r',system restart!!!");
	    	    restart();
	    	    break;	    	    
	    	default :break;
	    }
	    aa=0xff;
	    Delay(100);
	}
}
void Isr_Init(void)
{
	pISR_RESET=(unsigned)HaltReset;
	pISR_UNDEF=(unsigned)HaltUndef;
    pISR_SWI  =(unsigned)HaltSwi;
    pISR_PABORT=(unsigned)HaltPabort;
    pISR_DABORT=(unsigned)HaltDabort;
    
    rINTCON=0x5;    //Non-vectored,IRQ enable,FIQ disable 
    rINTMOD=0x0;    //All=IRQ mode
    rEXTINT=0x0;						// eint4567使能低电平触发 
    //uart rx int,eint4567 ,IIC enable
	rINTMSK=~( BIT_URXD0 | BIT_EINT4567 | BIT_IIC | BIT_TIMER2 |BIT_GLOBAL);
    /*pISR_FIQ,pISR_IRQ must be initialized*/
    pISR_URXD0=(unsigned)Uart0_RxInt;
    pISR_EINT4567=(int)Eint4567Isr;		//将外部中断4567产生的中断,指向函数Key_Init
    
}
void __irq Eint4567Isr(void)
{ 
	rINTMSK=~( BIT_URXD0 | BIT_EINT4567 | BIT_IIC | BIT_TIMER2 |BIT_GLOBAL);
	which_int = rEXTINTPND;			//获取中断源为中断4567中的哪一个
	rEXTINTPND=0XF;					//clear EXTINTPND reg.
	rI_ISPC=BIT_EINT4567;		//clear pending_bit
	rINTMSK=~( BIT_URXD0 | BIT_EINT4567 | BIT_IIC | BIT_TIMER2 |BIT_GLOBAL);
	 
}
void __irq Uart0_RxInt(void)
{
	rI_ISPC=BIT_URXD0;//clear pending bits,default value=0x00000000
	aa=RdURXH0();
}	
void HaltReset(void)
{
    Uart_Printf("reset exception!!!\n");
    restart();
}

void HaltUndef(void)
{
    Uart_Printf("Undefined instruction exception!!!\n");
    while(1);
}

void HaltSwi(void)
{
    Uart_Printf("SWI exception!!!\n");
    while(1);
}

void HaltPabort(void)
{
    Uart_Printf("Pabort exception!!!\n");
    while(1);
}

void HaltDabort(void)
{
    Uart_Printf("Dabort exception!!!\n");
    while(1);
}

⌨️ 快捷键说明

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