Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Eusart

Status
Not open for further replies.

rahul_37

New Member
will any 1 help me in writing c code for Eusart communication with pc using hyper link my code is dis but its not working like i want to display what i typed in my pc keyboard on 16*2 LCD pleas help me


/********************************************************************************************************************
Counter On Each Interrupt
Interrupt Pin Assign to RB0
Data Lines aer connected to port D D0 - D7
E = RE2
RS = RE0
RW = RE1
CONTROLLER USED PIC16F887
*******************************************************************************************************************/
#include <pic.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

__CONFIG (FOSC_INTRC_NOCLKOUT & WDTE_OFF & PWRTE_ON & MCLRE_ON & CP_ON & BOREN_ON & IESO_OFF & FCMEN_OFF & DEBUG_OFF);

#define PORTBIT(adr, bit) ((unsigned)(&adr)*8+(bit))

static bit RW @ PORTBIT(PORTE, 1);
static bit RS @ PORTBIT(PORTE, 0);
static bit ENA @ PORTBIT(PORTE, 2);
/***InitiallizeAll***/
void LCDDelay(unsigned int Delay);
void LCD_Display(void);
void InitialiseAll(void);
void clear_display(void);
void LCD_Initialliz(void);
void Nibble_seperat(void);
void debounce(void);


unsigned char Message1[17];
unsigned char Message2[17];
//void InitialiseAll(void);
unsigned char delaycount;
unsigned int i,J,K;
unsigned int Flag_1;
unsigned int DelayCount;
unsigned int num;
unsigned int temp;
unsigned int temp1;
unsigned int count;
unsigned int Int_Flag;
unsigned int a;
unsigned int Adc_Value;
unsigned int value;
unsigned int value1;
unsigned int b;
float t;




union abc
{
int count;
int Byte[2];
};
union abc ADC;


void main()
{

InitialiseAll();
LCD_Initialliz();
strcpy(Message1,"Degre Centigrade");
strcpy(Message2," C ");
LCD_Display();


for(i=0;i<65500;i++);
for(i=0;i<65500;i++);
for(i=0;i<65500;i++);
while(1)
{
if(RCIF)
{
temp1 = RCREG;
Nibble_seperat();
LCD_Display();
}

}

}

void InitialiseAll()
{
OSCCON=0B11100001;
// SPBRG = 25; // 9600 baud @ 8MHz
// TXSTA = 0x24; // setup USART transmit
// RCSTA = 0x90; // setup USART receive
PORTC = 0; // Clear PORTC
TRISC = 0X80; //
// TRISC = 0b11110010;

//
SPBRG=25;
RCSTA=0b10010000;
TXSTA=0b00100100;

T1CON=0X00;
CCP1CON=0X00;
CCP2CON=0X00;

OPTION_REG = 0b10000111; //1:256
ANSEL = 0b00000000;
ANSELH = 0b00000000;
ADCON0 = 0b00000000;
ADCON1 = 0b00000000;
CM1CON0 = 0b00000000;
CM2CON0 = 0b00000000;
INTCON = 0b11010000;
OSCCON = 0b01110001;
PORTA = 0;
TRISA = 0X00;

PORTB = 0;
TRISB = 0b00000000;

PORTD=0;
TRISD=0X00;

PORTE=0;
TRISE=0X00;
WPUB=0B11111111;
GIE=1;
PEIE=1;
}
void Nibble_seperat()
{
for(i=0;i<=2;i++)
{
temp=temp1%10;
temp1=temp1/10;
temp=temp+48;
Message2[9-i]=temp;
}
}


void LCD_Initialliz()
{
LCDDelay(80000);

PORTD=0X3B; // FUNCTION SET 8 BIT 2 LINES 5*8 DISPLAY
LCDDelay(100);

PORTD=0X3B; // FUNCTION SET 8 BIT 2 LINES 5*8 DISPLAY
LCDDelay(100);

PORTD=0X3B; // FUNCTION SET 8 BIT 2 LINES 5*8 DISPLAY
LCDDelay(200);




PORTD=0X0C; // DISPLAY ON
LCDDelay(100);

PORTD=0X01; // CLEAR DISPLAY
LCDDelay(2740);


PORTD=0X05; // ENTRY MODE
LCDDelay(100);


PORTD=0X03; // RETURN HOME
LCDDelay(100);

PORTD=0X17; // DISPLAY SHIFT.
LCDDelay(100);



}
void LCDDelay(unsigned int Delay)
{
ENA = 1;
for(i=0;i<Delay;i++);
ENA = 0;
}
void LCD_Display()
{
PORTD = 0x80; // Send Command to select Line 1
LCDDelay(500);
for(i=0;i<50;i++);
for(DelayCount=0;DelayCount<16;DelayCount++) // Display Line 1
{
RS = 1;
PORTD = Message1[DelayCount];
LCDDelay(500);
RS = 0;
}

PORTD = 0xC0; // Send Command to select Line 2
LCDDelay(500);
for(i=0;i<50;i++);
for(DelayCount=0;DelayCount<16;DelayCount++) // Display Line 2
{
RS = 1;
PORTD = Message2[DelayCount];
LCDDelay(500);
RS = 0;
}
}
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top