Stefanovic
Newbie level 6
Hello everybody,
I'm facing some stranges troubles with my simple UART c code.
My problem is that the first while of bonjour(); never ends, thus i cant send even the first byte. (
Here is the code,(no reception, just transmission) i really need help
thanks a lot !!
I'm facing some stranges troubles with my simple UART c code.
My problem is that the first while of bonjour(); never ends, thus i cant send even the first byte. (
Here is the code,(no reception, just transmission) i really need help
thanks a lot !!
Code:
#include <htc.h>
#include <pic18f87j10.h>
#include <stdio.h>
#include <stdlib.h>
//----PIC Configuration bits-----
#pragma config DEBUG = OFF // debugger off
#pragma config XINST = OFF // extended instruction set disabled
#pragma config STVREN = OFF // stack overflow interrupt disabled
#pragma config WDTEN = OFF // WDT disabled
#pragma config CP0 = OFF // code protection disabled
#pragma config FCMEN = OFF // fail safe clock monitor disabled
#pragma config IESO = OFF // internal/external clock switch disabled
#pragma config FOSC = HSPLL // HS oscillator (PLL enabled, software control)
#pragma config MODE = MM // Microcontroller mode
#pragma config ECCPMX = DEFAULT // Default setting for ECCP1
#pragma config CCP2MX = DEFAULT // Default setting for ECCP2
#pragma config FOSC2 = ON // Clock selected by OSCCON bits
void init_uart (void) {
OSCTUNE=0x40; //PLL x 4 with primary crystal at 10Mhz ==> 40Mhz with PLL
//----config port I/O-----
PORTB=0x00;
LATD=0x00;
TRISB=0x01; //RB0 out
PORTD=0x00;
LATD=0x00;
TRISD=0x00;
PORTC=0x00;
LATC=0x00;
TRISC=0x90; //RC7(RX) in, RC6(TX) out, ...
TXREG1=0x00;
RCREG1=0x00;
//----config regsitres uart----
TXSTA1=0x24; //TXEN=1, BRGH=1 high speed
BAUDCON1=0x08; //BRG16=1 (using two register to calculate Baud Rate)
SPBRGH1=0x00;
SPBRG1=0xAC; //
RCSTA1=0x90; // SPEN=1, CREN=1 serial port enabled,
}
void bonjour (void){
TXREG1='b';
while(TX1IF!=1){}
TXREG1='o';
while(TX1IF!=1){}
TXREG1='n';
while(TX1IF!=1){}
TXREG1='j';
while(TX1IF!=1){}
TXREG1='o';
while(TX1IF!=1){}
TXREG1='u';
while(TX1IF!=1){}
TXREG1='r';
while(TX1IF!=1){}
TXREG1=0x0A; //line feed ascii
}
void main (void) {
init_uart();
while(1){
bonjour();
}
}