CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

keypad input for analog signal

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
crushneck



Joined: 27 Nov 2005
Posts: 29

View user's profile Send private message MSN Messenger

keypad input for analog signal
PostPosted: Sun Feb 05, 2006 9:43 pm     Reply with quote

I need help on my project...i need to make it like when i press number 1 of my keypad, a current analog input shown in LCD...so also when i press 2,a voltage analog input shown in LCD..i try to edit the code...but the output is wrong...can sumone take a look at my source code...maybe u can help by editing it...thanks



Code:
#include <18F452.h>
#device adc=10
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,ERRORS)  //pin25=c6, pin26=c7

#include <lCD420.c>
#include <kbd.c>



void main() {
char k;
int16 result;
float adcresult;
port_b_pullups(TRUE);

lcd_init();
kbd_init();


setup_adc_ports(AN0);

setup_adc(ADC_CLOCK_DIV_8);

set_adc_channel(0);




while (TRUE) {

      result = read_adc();
   adcresult = (float)result * (5.0/1024.0);// a to d is 10 bits. 2^10=1024

 


      k=kbd_getc();
      if(k!=0)
         if(k=='1')//when 1 is pressed, current input shown
          lcd_gotoxy(1,2);
         printf(lcd_putc, "\n\r ADC (I): %5.2fmA\r\n", adcresult);
         delay_ms(100);

         if(k=='2')//when 2 is pressed, voltage input shown
         lcd_gotoxy(1,3);
         printf(lcd_putc, "\n\rADC (V):%5.3fV\r\n", adcresult);
         delay_ms(100);

         else
         lcd_putc(k);

   }
}


Last edited by crushneck on Thu Feb 09, 2006 11:29 am; edited 1 time in total
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Tue Feb 07, 2006 1:42 pm     Reply with quote

Some questions:

1) Why are you sending newline ('\n') and carriage-return ('\r') characters when you just told the LCD exactly where you wanted to start printing with the gotoxy() function?

2) You have a multi-line comment block started on the line with k=kbd_getc() and ending just before the else statement. I'm supprised the compiler isn't throwing an error but if it isn't then all you are doing is puting the contents of variable k on the lcd at the current position. k could hold any value from 0 to FF because you haven't initialized it or assigned a value. Did you mean to coment out that block of code?
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
crushneck



Joined: 27 Nov 2005
Posts: 29

View user's profile Send private message MSN Messenger

PostPosted: Tue Feb 07, 2006 7:37 pm     Reply with quote

Quote:
1) Why are you sending newline ('\n') and carriage-return ('\r') characters when you just told the LCD exactly where you wanted to start printing with the gotoxy() function?


Sorry i actually dun understand the characters. im new to this programming. can u explain more about the characters? i noe theres a help in PIC C compiler but i still dont get it.

Code:
2) You have a multi-line comment block started on the line with k=kbd_getc() and ending just before the else statement. I'm supprised the compiler isn't throwing an error but if it isn't then all you are doing is puting the contents of variable k on the lcd at the current position. k could hold any value from 0 to FF because you haven't initialized it or assigned a value. Did you mean to coment out that block of code?


yes. actually i want u to comment this part. i jus want to make it like when number 1 of my keypad, a current analog input shown in LCD. so also when i press 2,a voltage analog input shown in LCD.
crushneck



Joined: 27 Nov 2005
Posts: 29

View user's profile Send private message MSN Messenger

PostPosted: Thu Feb 09, 2006 2:04 am     Reply with quote

anyhelp anyone?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group