makwanamilan96
Newbie level 4
- Joined
- Apr 3, 2013
- Messages
- 6
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,315
My problem is similar to the problem listed below.
https://www.edaboard.com/threads/277534/
I can already display the value on LCD
But i want to display the value of adc on UART ,:roll:
Now let me tell my hardware info so that you can help.
i am using 8051 microcontroller (P89V51RD2)
interfaced with lcd and adc.
Adc gives digital value which is being displayed on LCD.
now i want to display this value on UART..
my current program is listed below
https://www.edaboard.com/threads/277534/
I can already display the value on LCD
But i want to display the value of adc on UART ,:roll:
Now let me tell my hardware info so that you can help.
i am using 8051 microcontroller (P89V51RD2)
interfaced with lcd and adc.
Adc gives digital value which is being displayed on LCD.
now i want to display this value on UART..
my current program is listed below
Code:
//Adc_potentiometer
#include <p89v51Rx2.h>
#include <stdio.h>
#define lcd_port P2 // Data port for LCD
//sfr SPCTL = 0xD5; //SPI CONTROL REG; SPI INTERRUPT ENABLE=1,SPI SYSTEM ENABLE=1, SPI MASTER MODE=1
//sfr SPCFG = 0XAA; // SPI STATUS REG; SPIF Interrupt Flag=1 ,SPI Transmit Empty Interrupt Flag=1 ,MODF=0
//sfr SPDAT = 0X86; //SPI Data Register'S sfr ADDRESS
sbit SS = P1^4;
sbit rs = P3^6;
sbit en = P3^7;
rw=0;
void delay(unsigned int msec) // Function for delay
{
int i,j;
for(i=0;i<msec;i++)
for(j=0; j<110; j++);
}
//CPHA - SPI Clock Phase Bi, SSOE - Slave Select Output Enable,LSBFE - LSB-First Enable
void lcd_cmd(unsigned char item) // Function to send command on LCD
{
lcd_port = item;
rs= 0;
rw=0;
en=1;
delay(1);
en=0;
return;
}
void lcd_data(unsigned char item) // Function to display character on LCD
{
lcd_port = item;
rs= 1;
rw=0;
en=1;
delay(1);
en=0;
return;
}
void lcd_init()
{
lcd_cmd(0x38); // For using 8-bit 2 row LCD
delay(5);
lcd_cmd(0x0F); // For display on cursor blinking
delay(5);
lcd_cmd(0x80); // Set the cursor on first position of LCD
delay(5);
lcd_cmd(0x01); //clear the screen
}
void lcd_print(unsigned char x[],unsigned int l)
{
unsigned int i;
if(l==1)
{lcd_cmd(0x80); //start from location 0 line 1
delay(200);}
if(l==2) //force cursor to begin from 2nd line
{lcd_cmd(0xC0); //start from location 0 line 1
delay(200);}
for(i=0;x[i]!='\0';i++)
{
lcd_data(x[i]);
delay(20);
}
}
void spi_init()
{
SPCTL=0X5F; //SPI System Enable Bit ,SPI Master/Slave Mode Select Bit(Here master mode is selected),CPOL - SPI Clock Polarity Bit,
}
unsigned int ADC_Read()
{
union
{
unsigned int adc_int;
unsigned char adc_char[2];
}adc_value;
adc_value.adc_int = 0;
// P2 = 0x00;
SS = 0; //chip select is made low to initiate SPI
SPCFG=0X00;
SPDAT=0X00; //CHANNEL I/P FOR spi
while(SPCFG!= 0x80);
SPCFG=0;
SPDAT = 0XC0;
while(SPCFG!=0x80);
adc_value.adc_char[0] = SPDAT & 0x0F;
SPCFG = 0;
SPDAT = 0X00; //data is send to generate SCK signal
while(SPCFG!=0x80);
adc_value.adc_char[1] = SPDAT;
SPCFG = 0;
SS = 1;
// P2 = 0x01;
return(adc_value.adc_int);
}
void main ()
{
unsigned int adc_cnt;
char lcd_buf[16];
lcd_init();
spi_init();
while(1)
{
adc_cnt = ADC_Read();
sprintf(lcd_buf,"adc=%4d",adc_cnt);
lcd_print(lcd_buf,1);
}
}
Last edited: