Created
September 7, 2014 21:14
-
-
Save davilamds/c557835dc790d15e8a74 to your computer and use it in GitHub Desktop.
UART pic17f628a
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
/* | |
* File: serialasincrono.c | |
* Author: MIGUEL | |
* | |
* Created on 3 de septiembre de 2014, 10:07 p.m. | |
* | |
* Programa: Transmite las letras H,O,L,A en modo asíncrono 9600/8N1 | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include "serialasincrono.h" | |
#define _XTAL_FREQ 20000000 | |
/*============================================================================== | |
Inicializar puertos, esta función es llamada luego en el main(). | |
==============================================================================*/ | |
void initPorts(void) | |
{ | |
TRISB = 0b00000110; | |
} | |
void initUART(void) | |
{ | |
TXSTAbits.BRGH=0; | |
SPBRG=32; | |
TXSTAbits.SYNC=0; | |
RCSTAbits.SPEN=1; | |
TXSTAbits.TXEN=1; | |
} | |
void busyUART(void) | |
{ | |
ocupado: | |
if (PIR1bits.TXIF==0){ | |
goto ocupado; | |
} else return; | |
} | |
/*============================================================================== | |
Bucle principal | |
==============================================================================*/ | |
int main(void) | |
{ | |
// Inicializar puertos y periféricos | |
initPorts(); | |
initUART(); | |
// Repetir indefinidamente | |
while(1) | |
{ | |
busyUART(); | |
TXREG = 0b01001000; // ascii H | |
//_delay(1000000); | |
busyUART(); | |
TXREG = 0b01001111; // ascii O | |
//_delay(1000000); | |
busyUART(); | |
TXREG = 0b01001100; // ascii L | |
//_delay(1000000); | |
busyUART(); | |
TXREG = 0b01000001; // ascii A | |
//_delay(1000000); | |
busyUART(); | |
TXREG = 0b00001101; // | |
//_delay(1000000); | |
busyUART(); | |
TXREG = 0b00001010; | |
//_delay(1000000); | |
} | |
} | |
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
/* | |
* File: serialasincrono.h | |
* Author: MIGUEL | |
* | |
* Created on 3 de septiembre de 2014, 10:05 p.m. | |
*/ | |
// PIC16F628A 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: High-speed crystal/resonator on RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN) | |
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled) | |
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled) | |
#pragma config MCLRE = ON // RA5/MCLR/VPP Pin Function Select bit (RA5/MCLR/VPP pin function is MCLR) | |
#pragma config BOREN = ON // Brown-out Detect Enable bit (BOD enabled) | |
#pragma config LVP = OFF // Low-Voltage Programming Enable bit (RB4/PGM pin has digital I/O function, HV on MCLR must be used for programming) | |
#pragma config CPD = OFF // Data EE Memory Code Protection bit (Data memory code protection off) | |
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment