Is the code below correct ? , not working in 16F877a
Rich (BB code):
#include <stdio.h>
#include <htc.h>
#include "usart.h"
#ifndef _XTAL_FREQ
// Unless specified elsewhere, 4MHz system frequency is assumed
#define _XTAL_FREQ 20000000
#endif
__CONFIG( HS & WDTDIS & PWRTDIS & BORDIS & LVPDIS & WRTEN & DEBUGDIS & UNPROTECT);
/* A simple demonstration of serial communications which
* incorporates the on-board hardware USART of the Microchip
* PIC16Fxxx series of devices. */
void putch(unsigned char byte)
{
/* output one byte */
while(!TXIF) /* set when register is empty */
continue;
TXREG = byte;
}
unsigned char
getch() {
/* retrieve one byte */
while(!RCIF) /* set when register is not empty */
continue;
return RCREG;
}
unsigned char
getche(void)
{
unsigned char c;
putch(c = getch());
return c;
}
void main(void){
TRISD=0;
PORTD=0;
unsigned char input;
INTCON=0; // purpose of disabling the interrupts.
init_comms(); // set up the USART - settings defined in usart.h
while(1){
char rxbyte;
rxbyte= getch();
switch(rxbyte)
{
case '1':
PORTD=0xFF;
putch("hhh");
__delay_ms(20);
break;
case 'b':
PORTD=0x00;
putch("hhh");
__delay_ms(20);
break;
default :
break;
}
}
}