打印
[菜农助学交流]

第五批之5 GPIO LED BEEP UART

[复制链接]
1983|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
cnjxlxp|  楼主 | 2012-4-15 22:32 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 cnjxlxp 于 2012-4-15 22:34 编辑
#include <stdio.h>
#include "NUC1xx.h"
#include "DrvGPIO.h"
#include "DrvUART.h"
#include "DrvSYS.h"


uint8_t writechar1[1] ={0x55};//default write char
uint8_t getchar1;

//uart set//n,8,1,9600
void uart_init(void)
{
STR_UART_T param;
DrvSYS_SelectIPClockSource(E_SYS_UART_CLKSRC, 0);
DrvGPIO_InitFunction(E_FUNC_UART0);

param.u32BaudRate = 9600;
param.u8cDataBits = DRVUART_DATABITS_8;
param.u8cStopBits = DRVUART_STOPBITS_1;
param.u8cParity = DRVUART_PARITY_NONE;
param.u8cRxTriggerLevel = DRVUART_FIFO_1BYTES;
param.u8TimeOut = 0;
DrvUART_Open(UART_PORT0, ¶m);
}

void Sys_Init()
{

UNLOCKREG();
SYSCLK->WRCON.XTL12M_EN = 1;//12M
DrvSYS_Delay(5000);
LOCKREG();

uart_init();

DrvGPIO_Open(E_GPB, 10, E_IO_OUTPUT);//GPB10 output
DrvGPIO_ClrBit(E_GPB, 10);//if not clear GPB10, the buzzer will on. the default output is 0xffff;

DrvGPIO_Open(E_GPA,2, E_IO_OUTPUT); //GPA2 output, LED1
DrvGPIO_Open(E_GPA,3, E_IO_OUTPUT); //GPA3 output, LED2
}

void delay_ms(void)//delay form xiaobing's source code
{
uint32_t i,j;
for(i=1000;i>0;i--)
for(j=2395;j>0;j--);
}

int main (void)
{
Sys_Init();

while(1)
{
printf("hello world \n");//use printf to sent char from uart

DrvUART_Write(UART_PORT0,writechar1,1); //driver write uart
DrvSYS_Delay(5000);
printf("\n");

printf("input a char\n");//tell user to input a char
DrvSYS_Delay(5000);

while(UART0->ISR.RDA_IF==0);//stop here, till a char is received from uart to fifo
DrvUART_Read(UART_PORT0,writechar1,1);//driver read uart

DrvSYS_Delay(5000);
DrvUART_Write(UART_PORT0,writechar1,1);//driver write uart
DrvSYS_Delay(5000);
printf("\n");

printf("input a char\n");
DrvSYS_Delay(5000);//stop here, till a char is received from uart
getchar1=getchar();//use getchar to receive char from uart
DrvSYS_Delay(5000);
printf("the char you input is %c\n",getchar1);
DrvSYS_Delay(5000);
// scanf("%c\n",&getchar1);
getchar1=getchar();//use getchar to receive char from uart
DrvSYS_Delay(5000);
printf("the char you input is ");
putchar(getchar1);
DrvSYS_Delay(5000);
putchar('\n');
putchar('b');//use putchar to send char to uart
putchar('y');
putchar('e');
putchar('\n');

while(1)//led2 blinks, and buzzer on and off alternate
{
DrvGPIO_ClrBit(E_GPA,2);//GPA2=0
DrvGPIO_ClrBit(E_GPB, 10); //GPB10=0
delay_ms();

GPIOA->DOUT ^= 0x8; //LED2 turns on and off

DrvGPIO_SetBit(E_GPA,2);//GPA2=1
DrvGPIO_SetBit(E_GPB, 10);//GPB10=1
delay_ms();
}
}

}

未命名2.jpg (24.49 KB )

未命名2.jpg

未命名.jpg (39.71 KB )

未命名.jpg

未命名3.jpg (42.6 KB )

未命名3.jpg

未命名4.jpg (22.64 KB )

未命名4.jpg

未命名5.jpg (19.34 KB )

未命名5.jpg

GPIO LED BEEP UART.rar

1.02 MB

GPIO UART LED BEEP WORD.rar

185.92 KB

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

0

主题

46

帖子

2

粉丝