Code:
//File name:Lab1.c
//Student Name:Goh Chee Tatt
#define XTAL_FREQ 4MHZ
#include <htc.h>
#include "delay.h"
#include "lcd.h"
#include "usart.h"
#include <stdio.h>
#include <stdlib.h>
#define _XTAL_FREQ 4000000
/*Lab1.c - Turn ON PORT B 0 LED*/
__CONFIG(0x3f31);
unsigned long int i;
delay1s() {
for (i = 0; i < 30000; i++) {
NOP(); //no operation is carried out
}
}
unsigned char
getch() {
/* retrieve one byte */
while (!RCIF) /* set when register is not empty */
continue;
return RCREG;
}
void transmit_uart(const char *value) {
for(int i = 0; value != '\0'; i++) {
while(TXIF == 0) {}
TXREG = value;
}
}
main() {
TRISB = 0; //initialize portb as output
PORTB = 0; //set all pin of portb as low
TRISD = 0;
PORTD = 0;
lcd_init();
init_comms();
SPBRG = 25; //4MHz
TXSTA = 0x24;
RCSTA = 0x90;
//USART interrupt
RCIE = 1;
GIE = 1;
PEIE = 1;
char line[50];
char str [20];
char hai[10];
char hello[10];
char sai[10];
char jiak[10];
char you[10];
int n;
i=0;
n = sprintf(hai, "atmy1111");
transmit_uart(hai);
__delay_ms(200);
__delay_ms(10);
}
void interrupt usart(void) {
char go[50];
if (RCIE && RCIF) {
i=0;
go = getch();
lcd_putch(go);
}
}
Code:
hi guys i facing a problem in usart, i perform a loop test on my microcontroller , means sending data and receive data within a single microcontroller, however, when simulated using proteus software, i noticed that i received repeat number of same data, why it is so , doesnt i only send the data once? can someone explain?