sbit LCD_RS at RD2_bit; // Lcd module connections
sbit LCD_EN at RD3_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;
sbit LCD_RS_Direction at TRISD2_bit;
sbit LCD_EN_Direction at TRISD3_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
void main() {
int analog_value = 0; // define intiger "analog_value" with initial value of 0
int value = 0;
char buf [7];
TRISA.f0=1; // define AN0 pin as input
ADCON1 = 0; // set all pinns in register A as analog inputs with refference to VDD
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100);
while(1)
{
analog_value = ADC_Read(0);
value = (int)((analog_value/204.6)*1000);
intToStr(value,buf);
ltrim(buf);
UART1_write_text(buf);
Lcd_Out(1,1,buf);
Delay_ms(5000);
}
}
sbit LCD_RS at RD2_bit; // Lcd module connections
sbit LCD_EN at RD3_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;
sbit LCD_RS_Direction at TRISD2_bit;
sbit LCD_EN_Direction at TRISD3_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
char value ;
void main() {
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize
while (1) { // Endless loop
if (UART1_Data_Ready()== 1)
{
value = UART1_Read(); // read the received data,
Lcd_chr_CP(value);
}
}
}
Code C - [expand] 1 UART1_Read_Text()
Code C - [expand] 1 UART1_Write_Text()
Useat the receiving side. Don't forget to use
Code C - [expand] 1 UART1_Read_Text()
at the transmitting side with the delimiter. If you want to send 123.45678 then send it as "123.45678\r\n" and at the receiver end check for the delimiter \r\n.
Code C - [expand] 1 UART1_Write_Text()
char *res; // at the beginning
res = strcat(buf, "\r\n");
ltrim(buf);
UART1_write_text(res);
Lcd_Out(2,1,res);
char *output; // at the beginning
UART1_Read_Text(output,"/r/n", 255); // instead of UART1_read
Lcd_Out(2,1,output);
Code C - [expand] 1 2 3 4 5 len = strlen(buf); buf[len - 1] = 0x0D; buf[len] = 0x0A; buf[len + 1] = '\0'; UART1_write_text(buf);
Code C - [expand] 1 2 3 4 5 len = strlen(buf); buf[len - 1] = 0x0D; buf[len] = 0x0A; buf[len + 1] = '\0'; UART1_write_text(buf);
Code C - [expand] 1 UART1_Read_Text(output,"\r\n", 15);
char *output; // at the beginning
UART1_Read_Text(output,"/r/n", 255); // instead of UART1_read
Lcd_Out(2,1,output);
char output[16];
A popular C fault: Storing data to a nowhere-string
Code:char *output; // at the beginning UART1_Read_Text(output,"/r/n", 255); // instead of UART1_read Lcd_Out(2,1,output);
Instead of a pointer, define s string variable, e.g.
Code:char output[16];
Try this. Zip and post your mikroC project files + Proteus file. I just don't have time to create a new project. Have you read mikroC help regarding minimum array size to be used withfunctions?
Code C - [expand] 1 IntToStr() or FloatToStr()
Try this code
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?