Created
June 13, 2014 03:15
-
-
Save murilopontes/cf1e0c3e380885d0f4e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//////////////////////////////////////////////////////////////////////////////// | |
// PIC16F876A Configuration Bit Settings | |
// 'C' source line config statements | |
#include <xc.h> | |
// #pragma config statements should precede project file includes. | |
// Use project enums instead of #define for ON and OFF. | |
// CONFIG | |
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator) | |
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled) | |
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled) | |
#pragma config BOREN = OFF // Brown-out Reset Enable bit (BOR enabled) | |
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3/PGM pin has PGM function; low-voltage programming enabled) | |
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off) | |
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control) | |
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off) | |
//////////////////////////////////////////////////////////////////////////////// | |
#include <stdio.h> | |
#include <stdlib.h> | |
// crystal 20mhz capacitors 15pF | |
#define _XTAL_FREQ 20000000 | |
// | |
void Delay1Second() | |
{ | |
int i; | |
for(i=0;i<100;i++) | |
{ | |
__delay_ms(10); | |
} | |
} | |
char txt[10]; | |
void usart_string(char *str) | |
{ | |
while(*str!='\0') | |
{ | |
while(!PIR1bits.TXIF); | |
TXREG=(*str); | |
str++; | |
} | |
} | |
/* | |
void interrupt ISR(void) | |
{ | |
// | |
if (RCIE && RCIF) { | |
char data=RCREG; | |
return; | |
} | |
} | |
*/ | |
void usart_init(){ | |
/* | |
UART>(4) | |
Waiting activity... | |
Calculated: 60606 bps | |
Estimated: 57600 bps | |
UART> | |
*/ | |
TRISC6 = 0; //TX pin set as output | |
TRISC7 = 1; //RX pin set as input | |
SPBRG=129; | |
//TXSTA | |
TXSTAbits.TX9=0; //8 bit transmission | |
TXSTAbits.TXEN=1; //Transmit enable | |
TXSTAbits.SYNC=0; //Async mode | |
TXSTAbits.BRGH=1; //High speed baud rate | |
//RCSTA | |
RCSTAbits.SPEN=1; //Serial port enabled | |
RCSTAbits.RX9=0; //8 bit mode | |
RCSTAbits.CREN=0; //Enable receive | |
RCSTAbits.ADDEN=0; //Disable address detection | |
//Receive interrupt | |
//RCIE=1; | |
//PEIE=1; | |
// | |
//ei(); | |
} | |
void led_init(){ | |
TRISA0=0; | |
} | |
void led_state(int i){ | |
RA0=(i%2); | |
} | |
const char* txt2 = "teste\r\n"; | |
int main(int argc, char** argv) { | |
usart_init(); | |
led_init(); | |
int i=0; | |
while(1) | |
{ | |
led_state(i); | |
// | |
sprintf(txt,"%d\r\n",i); | |
// | |
usart_string(txt2); | |
// | |
Delay1Second(); | |
// | |
i++; | |
} | |
return (EXIT_SUCCESS); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment