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

printf and lcdputc

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



Joined: 20 Apr 2008
Posts: 3

View user's profile Send private message

printf and lcdputc
PostPosted: Sun May 18, 2008 12:48 pm     Reply with quote

Hello everybody !!

I am new in this forum and this is my first post. I have to say that this forum is very useful and I have found answers to 99.9% of my questions.

Presently, I am writing a program which takes values incoming into the R232 and then it sends them to a LCD.
My program is running well except that when I use the printf mixed with Lcd_putc, it send some random data on the RS232 port

Code:
 printf(lcd_putc,"%s",input_str);


As I am using hyperterminal and the function my_get_string, I have to send manually some backspace in order to send a valid set of data.

I am using a pcidem4 board.

Is there some body have any suggestions to improve this situation ?

thanks in advance for the help

Here is my code :

Code:

#include <18f1320.h>
#fuses NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP,H4,NOMCLR,NOFCMEN
#use delay(clock=16000000)   
#include "flex_lcd.c"
#include "stdlib.h"
#use rs232(baud=9600, xmit=PIN_B1, rcv=PIN_B4)

#define BUFFER_SIZE 40
#define bkbhit (next_in!=next_out)
#define STRING_SIZE 11

BYTE buffer[BUFFER_SIZE];
BYTE next_in = 0;
BYTE next_out = 0;

#int_rda
void serial_isr()
  {
    int t;
    buffer[next_in]=getc();
    t=next_in;
    next_in=(next_in+1) % BUFFER_SIZE;
    if(next_in==next_out) next_in=t;           // Buffer full !!
  }

BYTE bgetc()
 {
   BYTE c;
   while(!bkbhit) ;
   c=buffer[next_out];
   next_out=(next_out+1) % BUFFER_SIZE;
   return(c);
 }


void my_get_string(char* s, unsigned int8 max)
 {
   unsigned int8 len;
   char c;
   --max;
   len=0;
   putc(0x0D);
   putc(8);
   putc(8);
   do
    {
      c = bgetc();   // Call bgetc() instead of getc()
      if(c==8)
       {             // Backspace
         if(len>0)
          {
            len--;
            putc(c);
            putc(' ');
            putc(c);
          }
       }
     else if ((c>=' ')&&(c<='~'))
      if(len<=max)
       {
         s[len++]=c;
         putc(c);
       }
    }
   while(c!=13);
   s[len]=0;
  }

//===================================
void main()
{

char input_str[STRING_SIZE];
int32 value;
byte byte0,byte1,byte2,byte3;
float temps;

enable_interrupts(int_rda);
enable_interrupts(global);

lcd_init();
lcd_putc("\fAlpha pulsing ");
lcd_putc("\nIBA (C) ver 1.0");
output_High(PIN_B3);
delay_ms(2000);
lcd_gotoxy(1,1);
lcd_putc ("rate :          ");

while(1)
  {
   enable_interrupts(int_rda);
   output_High(PIN_B3);
   printf("\f\r\n");
   my_get_string(input_str, STRING_SIZE-1);
   disable_interrupts(int_rda); 

   if (input_str[0]=='R')
    {
      input_str[0]='0';
      value = atoi32(input_str);
      byte0 = make8(value,0);
      byte1 = make8(value,1);
      byte2 = make8(value,2);
      byte3 = make8(value,3);   
      input_str[0]=' ';
      lcd_gotoxy(7,1);
      Lcd_putc("          ");
      lcd_gotoxy(7,1);
      printf(lcd_putc,"%s",input_str);

    }
  }

}
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