📄 main1.c
字号:
#include <string.h>
#include <math.h>
#include "option.h"
#include "def.h"
#include "44b.h"
#include "44blib.h"
#define READ_COUNT2 (rTCNTO2 & 0xffff)
//extern int Uart_GetIntNum(void);
void SetBeepPwm(void);
void StopBeepPwm(void);
void __irq TIMER2_int(void);
void Isr_Init(void);
void HaltUndef(void);
void HaltSwi(void);
void HaltPabort(void);
void HaltDabort(void);
int pwmcnt=0;
void Main(void)
{
//U8 aa;
//char ch[100];
//int i=0;
rSYSCFG=SYSCFG_8KB;
#if (PLLON==1)
ChangePllValue(PLL_M,PLL_P,PLL_S);
#endif
Isr_Init();
Port_Init();
Uart_Init(0,115200);
//Uart_Select(1);
Delay(0); //calibrate Delay()
Led_Display(7);
Delay(1000); //calibrate Delay()
Led_Display(0);
Delay(5000); //calibrate Delay()
Led_Display(7);
/*Uart_Printf("\n start \n");
Uart_Printf("\nHello,FS44B0X!");
Uart_Printf("\nPlease Press 'a'or'b'or'c'");*/
while(1)
{
SetBeepPwm();
Uart_SendByte(97);
Led_Display(0x2);
Delay(5000);
Uart_SendByte(98);
Led_Display(0x0);
Delay(5000);
Uart_SendByte(99);
Led_Display(0x4);
Delay(5000);}
}
/* witch(aa)
{
if(aa='a')
case 'a':
Uart_Printf("\nYou Pressed 'a'");
Led_Display(0x4);
break;
case 'b':
Uart_Printf("\nYou Pressed 'b'");
Led_Display(0x2);
break;
case 'c':
Uart_Printf("\nYou Pressed 'c'");
Led_Display(0x4);
break;
case 0x1b:
Led_Display(0x0);
break;
default :
break;
}*/
void SetBeepPwm(void)
{
rTCON &= 0xffff0fff; // clear manual update bit, stop Timer2
rTCFG0 &= 0xffff00ff;; // set Timer 2&3 prescaler 0
rTCFG1 &= 0xfffff0ff; // set Timer 2 MUX 1/16
rTCFG1 |= 0x00000300;
rTCNTB2 &= 0x0000006c; //十进制:108
rTCMPB2 &= 0x00000036; //十进制:54
rTCON |= 0x00002000; // manual update
rTCON &= 0xffff0fff; // clear manal update bit
rTCON |= 0x0000d000; // auto reload, inverter on, start Timer 2
}
void StopBeepPwm(void)
{
rTCON &= ~0x1000;
}
void __irq TIMER2_int(void)
{
rI_ISPC=BIT_TIMER2;
pwmcnt++;
return;
}
void Isr_Init(void)
{
U32 i;
pISR_UNDEF=(unsigned)HaltUndef;
pISR_SWI =(unsigned)HaltSwi;
pISR_PABORT=(unsigned)HaltPabort;
pISR_DABORT=(unsigned)HaltDabort;
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_EINT3; // All interrupt is masked. rINTCON = 5;
//rINTMOD = 0;
rINTMSK=~(BIT_GLOBAL|BIT_TIMER2);
pISR_TIMER2= (unsigned int)TIMER2_int; //(unsigned)
rPDATE = 0x157; //Beep = 10
rPCONE = 0x596b; // tout2
rPUPE = 0xff;
}
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 + -