码迷,mamicode.com
首页 > 其他好文 > 详细

PIC18F4520 UART模板

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

标签:c   class   blog   code   a   int   

如题

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模板

标签:c   class   blog   code   a   int   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!