#include "main.h"
#include "ac780x_gpio.h"
#include "ucos_ii.h"
#include "ac780x_uart.h"
#include "ac780x_uart_reg.h"
static OS_STK s_task0Stk [Task0StkLengh]; /* Define the DemoTask0 stack */
static OS_STK s_task1Stk [Task1StkLengh]; /* Define the DemoTask1 stack */
#define KEY_PRESS (GPIO_LEVEL_LOW)
#define KEY_RELEASE (GPIO_LEVEL_HIGH)
#define KEY6_PORT (GPIOC)
#define KEY6_PIN (GPIO_PIN6)
#define KEY7_PORT (GPIOA)
#define KEY7_PIN (GPIO_PIN11)
#define GET_KEY6_STS() (GPIO_GetPinLevel(KEY6_PORT, KEY6_PIN))
#define GET_KEY7_STS() (GPIO_GetPinLevel(KEY7_PORT, KEY7_PIN))
uint32_t TT;
uint32_t NG;
void mydelay()
{
uint16_t nn=0;
for(nn=0;nn<3000;nn++)
{
}
}
void EXTI_Key6_Callback(void *device, uint32_t wpara, uint32_t lpara)
{
if (GET_KEY6_STS() == KEY_PRESS)
{
TT=TT+1;
NG=NG+1;
}
}
void EXTI_Key7_Callback(void *device, uint32_t wpara, uint32_t lpara)
{
if (GET_KEY7_STS() == KEY_PRESS)
{
TT=TT+1;
}
}
void KEY_Init(void)
{
GPIO_SetFunc(KEY6_PORT, KEY6_PIN, GPIO_FUN0);
GPIO_SetFunc(KEY7_PORT, KEY7_PIN, GPIO_FUN0);
GPIO_SetDir(KEY6_PORT, KEY6_PIN, GPIO_IN);
GPIO_SetDir(KEY7_PORT, KEY7_PIN, GPIO_IN);
GPIO_SetPullup(KEY6_PORT, KEY6_PIN, ENABLE);
GPIO_SetPullup(KEY7_PORT, KEY7_PIN, ENABLE);
GPIO_EnableExternalInterrupt(KEY6_PORT, KEY6_PIN, EXTI_TRIGGER_FALLING);
GPIO_EnableExternalInterrupt(KEY7_PORT, KEY7_PIN, EXTI_TRIGGER_FALLING);
GPIO_SetCallback(KEY6_PIN, EXTI_Key6_Callback);
GPIO_SetCallback(KEY7_PIN, EXTI_Key7_Callback);
}
void UART1_Init(void)
{
GPIO_SetFunc(GPIOA,GPIO_PIN4, GPIO_FUN3);
GPIO_SetFunc(GPIOA,GPIO_PIN5, GPIO_FUN3);
CKGEN_Enable(CLK_UART1, ENABLE);
CKGEN_SoftReset(SRST_UART1, ENABLE);
UART_SetDivisor(UART1, (float)APB_BUS_FREQ / 16 / 9600);
UART_SetDataBits(UART1, UART_WORD_LEN_8BIT);
UART_SetStopBit(UART1, UART_STOP_1BIT);
UART_EnableTX(UART1, ENABLE);
UART_EnableRX(UART1, ENABLE);
UART_Set2ByteFIFO(UART1, ENABLE);
UART_SetInterruptEn(UART1, 9);
}
int main(void)
{
TT=0;
NG=0;
UART1_Init();
KEY_Init();
SysTick_Config(SYSTICK_CLOCK);
OSInit();
OSTaskCreate(DemoTask0, (void *)0, &s_task0Stk[Task0StkLengh - 1], Task0Prio);
OSTaskCreate(DemoTask1, (void *)0, &s_task1Stk[Task1StkLengh - 1], Task1Prio);
OSStart();
return 0;
}
void DemoTask0(void *pdata)
{
uint8_t SendBuf[11];
uint8_t ll=0;
SendBuf[0]='n';
SendBuf[1]='0';
SendBuf[2]='.';
SendBuf[3]='v';
SendBuf[4]='a';
SendBuf[5]='l';
SendBuf[6]='=';
SendBuf[7]='1';
SendBuf[8]=0xff;
SendBuf[9]=0xff;
SendBuf[10]=0xff;
while (1)
{
SendBuf[7]=TT+0x30;
for (ll=0;ll<11;ll++)
{
UART_SendData(UART1, SendBuf[ll]);
mydelay();
}
OSTimeDly(97);
}
}
void DemoTask1(void *pdata)
{
uint8_t SendBuf[11];
uint8_t ll=0;
SendBuf[0]='n';
SendBuf[1]='1';
SendBuf[2]='.';
SendBuf[3]='v';
SendBuf[4]='a';
SendBuf[5]='l';
SendBuf[6]='=';
SendBuf[7]='1';
SendBuf[8]=0xff;
SendBuf[9]=0xff;
SendBuf[10]=0xff;
while (1)
{
SendBuf[7]=NG+0x30;
for (ll=0;ll<11;ll++)
{
UART_SendData(UART1, SendBuf[ll]);
mydelay();
}
OSTimeDly(103);
}
}
好嘞,收到~