欢迎来到天天文库
浏览记录
ID:10243061
大小:35.50 KB
页数:3页
时间:2018-06-13
《uart初始化函数及其使用》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、串口函数总结串口的初始化voidUART0_Init(intmclk,intbaud){if(mclk==0)mclk=MCLK;rPCONE=0x28;rULCON0=0x3;rUCON0=0x245;rUBRDIV0=((int)(mclk/16./baud+0.5)-1);}voidUART1_Init(intmclk,intbaud){if(mclk==0)mclk=MCLK;rPCONE=0x28;rULCON0=0x3;rUCON0=0x245;rUBRDIV0=((int)(mcl
2、k/16./baud+0.5)-1);}查询方式发送数据voidUART0_SendByte(uint8data){rUTXH0=data;while((rUTRSTAT0&0x2)==0);}查询方式接收VoidUART0_RcvByte((uint8data){uint8rcv_data;while((rUTRSTAT0&0x01)==0);rcv_data=rURXH0;return(rcv_data);}使用外部中断发送和接收字符的函数:#include"44blib.h"#includ
3、e"44b.h"#include"stdio.h"voidMain(void);externvoidEint4567Isr(void)__attribute__((interrupt("IRQ")));voidinit_Eint(void);voidMain(void){sys_init();/*初始化s3c44B0XInterrupt,PortandUART*/_Link();init_Eint();Uart_Printf("rEmbest44B0XEvaluationBoard(S3C
4、EV40)");Uart_Printf("r8-segmentDigitLEDTestExample(PleaselookatLED)");for(;;){;}}#include"44b.h"#include"44blib.h"voidEint4567Isr(void)__attribute__((interrupt("IRQ")));voidinit_Eint(void);externvoidDelay(inttime);voidinit_Eint(void){rI_ISPC=0x3
5、ffffff;rEXTINTPND=0xf;//clearEXTINTPNDregrINTMOD=0x0;rINTCON=0x1;rINTMSK=~(BIT_GLOBAL
6、BIT_EINT4567);pISR_EINT4567=(int)Eint4567Isr;/*PORTG*/rPCONG=0xffff;//EINT7~0rPUPG=0x0;//pullupenablerEXTINT=rEXTINT
7、0x22220000;//EINT1、EINT4567fallingedgemoderI_IS
8、PC
9、=BIT_EINT4567;rEXTINTPND=0xf;//clearEXTINTPNDreg}voidEint4567Isr(void){chari;unsignedcharwhich_int;which_int=rEXTINTPND;rEXTINTPND=0xf;//clearEXTINTPNDreg.rI_ISPC=BIT_EINT4567;//clearpending_bitif(which_int==4)//SB2{Uart_Printf("发送:");Uart_SendB
10、yte('*');}elseif(which_int==8)//SB3{Uart_Printf("接收:");i=Uart_Getch();Uart_Printf("%c",i);}}
此文档下载收益归作者所有