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

📄 function.c

📁 2410bios 实现简单功能 裸板传输 跑马灯 定时器
💻 C
字号:
#include "def.h"
#include "2410addr.h"
#include "2410lib.h"
#include "2410slib.h"
#include "mmu.h"
#include "uart.h"
#include "timer.h"
#include "39vf160.h"
#include "LCD.h"
#include "PowerManage.h"

void Led(void);
void Key(void);
void Uart(void);
void Rtc(void);
void Pwm(void);
void Timer(void);
void Speaker(void);
void IntInit(void);
void service(void);
void uart_init(void);
void in_out(void);
void timer_init(void);
void timer_service(void);
void gets(char*);
U8 Esc(void);

#define ESC 27

struct {
		void (*fun)(void);
		char *tip;
		}list[] = { {Led, "Led"},{Key, "Key"},{Uart, "Uart"},{Rtc, "Rtc"},{Pwm, "Pwm"},
					{Timer, "Timer"},{Speaker, "Speaker"},{0, 0}	
			 	  };
/********************************
function()	 选择函数并调用
********************************/
void Function()
{
	while(1)
	{
		int i=0;
		U8 idx;
		puts("\nPlease select function \n");
		for(i=0; list[i].fun!=0; i++)
			printf("%d : %s\n", i, list[i].tip);
		
		idx = getch();
		
		if(idx != ESC )
		{	
			idx -= '0';
			if(idx<i)
			{
				(*list[idx].fun)();
			}
		}
		else 
			break;
	}
}
/*******************************
Esc()   按ESC 键立即退出
*******************************/
U8 Esc()
{
	U8 key =0;
	key =getkey();
	if(key == ESC)
		return 1;
	else
		return 0;
}

/********************************
Led()   跑马灯
********************************/
void Led()
{
	printf("you are in Led() now!\n");
	rGPFCON &= 0x00ff;
	rGPFCON |= 0x5500;
	rGPFDAT |= 0xf0;
	rGPFUP =0x00;
	while(1)
	{	
		int i;
		for(i=4;i<8;i++)
		{
			rGPFDAT |= 0xf0;
			rGPFDAT &= ~(1<<i);
			Delay(1000);
		}
		if(Esc()) 
			break;
	}
}

/********************************
Key()  键盘中断
********************************/
void Key()
{
		puts("you are in Key() now!\n");
		pISR_EINT0 =(U32)service;
		pISR_EINT2 =(U32)service;
		pISR_EINT8_23=(U32)service;
		while(1)   
		{
			IntInit();
			if(Esc()) 
				break;
		}
}


/********************************
Uart()  串口中断
*********************************/
void Uart()
{
	puts("you are in Uart() now!\n");
	
	pISR_UART1 =(U32)in_out;  

	while(1)
	{	
		uart_init();
		if(Esc()) 
			break;
	}
}

/********************************
Rtc()   设置时间
*********************************/
	void SetTime()			
	{
		rBCDSEC =0x0;
		rBCDMIN =0x7;
		rBCDHOUR=0x10;
		rBCDDATE=0x16;
		rBCDMON =0x4;
		rBCDYEAR=0x6;
	}
	
	void SetRtc()
	{
		int i =0;
		char time[13];
		puts("put in year,mon,date,hour,min,sec\n");
		gets(time);
		
		for(i=0;i<12;i++)
		{
			time[i] -=48;
		}
		
		rBCDYEAR= time[0]*16 + time[1];
		rBCDMON = time[2]*16 + time[3];
		rBCDDATE= time[4]*16 + time[5];
		rBCDHOUR= time[6]*16 + time[7];
	    rBCDMIN = time[8]*16 + time[9];
		rBCDSEC = time[10]*16 + time[11];
	}

	void Disp()
	{	
		printf("0%x:%x:%x:%x:%x:%x\n",rBCDYEAR,rBCDMON,rBCDDATE,rBCDHOUR,rBCDMIN,rBCDSEC);	 
	}
void Rtc()
{
	SetTime();
	
	while(1)
	{	
		int i = rBCDSEC;
		while(i == rBCDSEC);
		Disp();
		if(Esc()) 
			break;
	}
}

/********************************
Pwm()   每秒输出
*********************************/
void Pwm()
{
	puts("you are in Pwm() now!\n");
	pISR_TIMER2 = (U32)timer_service ;   	
	timer_init();
	while(1)
	{
		if(Esc()) 
			break;
	}
}




/********************************
Timer()  每秒输出
*********************************/
void Timer()
{
	puts("you are in Timer() now!\n");
	pISR_TIMER2 = (U32)timer_service ;
	timer_init();
	while(1)
	{
		if(Esc())
			break;
	}
}



/********************************
Speaker()  蜂鸣器
*********************************/
void Speaker()
{	
	int f=30000;
	puts("you are in Speaker() now!\n");
	rGPBCON &= ~0x3;
	rGPBCON |=  0x2;

	rTCFG0 &=~0xff;	  //预分频器
	rTCFG0 |=200;
	
	rTCFG1 &= ~ 0Xf;    //分割器 1/16
	rTCFG1 |= 0x3;

	while(1)
	{
		if(getch() == '+')
		{
			f+=200;
		}
		if(getch() == '-')
		{
			f-=200;
		}


		rTCNTB0 =96000000 / 200 / 16 / f;
		rTCMPB0 =rTCNTB0 * 0.5;

		rTCON &=~0x1f;
		rTCON |=0xb ;
		rTCON &=~2;	
		
		if(Esc()) 
			break;
	}
}

/********************************
Eth0()  网卡
*********************************/
void Eth0()
{
	puts("you are in Eth0() now!\n");
	
	
	
	while(1)
	{
		if(Esc()) 
			break;
	}
}






⌨️ 快捷键说明

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