首页 > 代码库 > PIC18F4520 UART模板
PIC18F4520 UART模板
如题
MPLAB V8.53 PIC18F4520 8bit MCU
#define USE_AND_MASKS #include <stdio.h> #include <stdlib.h> #include <delays.h> #include <usart.h> #pragma config OSC = INTIO67 //internal oscillator #pragma config WDT = OFF //watchdog timer off #pragma config LVP = OFF //... #pragma config PBADEN = OFF //Analog functions on PORTB OFF void initUART(void); void setClock(void); unsigned char msg[] = "Hello"; /* * main function */ void main() { setClock(); initUART(); while(1) //infinite loop { putsUSART(msg); Delay10KTCYx(125); } } /** * Initialise registers and pins for uart */ void initUART() { int baud = 51; // set baud rate to 9600 unsigned char UART1Config = USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_BRGH_HIGH; //TRISCbits.RC6 = 0; //TX pin set as output //TRISCbits.RC7 = 1; //RX pin set as input TRISC = 0x00 + (1 << 7); OpenUSART(UART1Config,baud); } /* * Setup the clock */ void setClock() { OSCCONbits.IRCF0 = 1; //internal oscillator to 8MHz OSCCONbits.IRCF1 = 1; OSCCONbits.IRCF2 = 1; }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。