uart communication for an accountant

Post your requests and ideas on the future development of mikroC PRO for ARM.
Post Reply
Author
Message
Rowskid
Posts: 1
Joined: 21 Jun 2014 01:05

uart communication for an accountant

#1 Post by Rowskid » 21 Jun 2014 01:25

hi all, I need to make a counter (a) through (z) with two push button one increases the alphabet and the other that the decrease and turn these printed on a lcd therefore I use a vector but the only letters sent to the lcd shows x. What is the problem?
this is the code:
notes:ignore the comments
I use proteus for circuits

int vector[26] = {65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90} ;
int counter=0;
int valor;
char cvalor[8];
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections


void main() {

ADCON1=15; // E/S DIGITALES
TRISB=0; // PUERTO B COMO SALIDA
PORTB=0; // PUERTO B EN ESTADO 0
TRISA=7; // PRIMEROS 3 BITS DEL PUERTO A COMO ENTRADA
PORTA=0; // PUERTO A EN ESTADO 0

//Inicializamos librería de LCD y le quitamos el cursor
LCD_Init();
Lcd_Cmd(_LCD_CURSOR_OFF); //Limpia el texto Iniciando
Lcd_Out(1,1,"Iniciando");
delay_ms(1000); //2 seg.
Lcd_Cmd(_LCD_CLEAR);

while(1){

if(counter>25){ //Mantener el rango 0 a 25 del contador
counter=25;
}

if(counter<0){ //Mantener el rango 0 a 25 del contador
counter=0;
}

if(porta==1){
counter++;
delay_ms(250);
valor=vector[85];
IntToStr(valor,cvalor);

Lcd_Chr_Cp(cvalor);
}

if(porta==2){
counter--;
delay_ms(250);
valor=vector[counter];
IntToStr(valor,cvalor);

Lcd_Chr_Cp(cvalor);
}

if(porta==4){
Lcd_Cmd(_LCD_CLEAR);
delay_ms(250);
}



//Fin del while
}
//Fin del void main
}

Jim Walsh
Posts: 55
Joined: 06 Mar 2014 01:38
Location: Pittsburgh, PA

Re: uart communication for an accountant

#2 Post by Jim Walsh » 21 Jun 2014 13:24

Hi,

I'm not a pro mind you 8) , but here are a couple things I noticed...

Code: Select all

if(porta==1){ <---- if you're checking a specific button you should check bit by bit (porta.b0 etc.)
counter++;    <----- this increases the counter before setting valor, so it will always be 1 ahead of what you expect
delay_ms(250);
valor=vector[85];   <--- This is probably just a typo...but it's always going to be 85 like this   :) 
IntToStr(valor,cvalor);  <--- you're converting to a string but...

Lcd_Chr_Cp(cvalor);  <--- ...sending to LCD using Lcd_Chr_Cp
}

Actually to send the character to the LCD you don't need to convert it...since you already set valor to the ASCII code for the letter, you can just send it to the LCD like it is. Something like this should work...

Code: Select all

if(porta.b0==1){
valor=vector[counter];
counter++;
delay_ms(250);
Lcd_Chr_Cp(valor);
}

Peace,
Jim

Post Reply

Return to “mikroC PRO for ARM Wish List”