首页 > 其他 > 详细

PIC18F4520 UART模板

时间:2014-06-01 11:16:23      阅读:483      评论:0      收藏:0      [点我收藏+]

如题

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; 
} 


PIC18F4520 UART模板,布布扣,bubuko.com

PIC18F4520 UART模板

原文:http://blog.csdn.net/metalseed/article/details/27707825

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!