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

PIC to LCD - again

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



Joined: 14 Mar 2007
Posts: 12

View user's profile Send private message ICQ Number

PIC to LCD - again
PostPosted: Thu Mar 15, 2007 2:52 pm     Reply with quote

Hello,

I am working on a senior design project that will use 18F452. Project will include A/D conversion at some point.

I will have relatively simple questions and I hope somebody could reply me
I am using CCS C 4.023 (our school has a licence) and I am just trying to send A/D data to an LCD.

I tried to use PIC Wizard as an aid, but I think it adds some unnecessary "disable" lines so I removed some of them.

My code is

Code:
 #include "F:\Program Files\PICC\Projects\LCD3\lcd3.h"
  #include <stdio.h>


/*#define LCD_ENABLE_PIN PIN_B0
#define LCD_RS_PIN PIN_B1
#define LCD_RW_PIN PIN_B2
*/

#include <lcd.c>
void main()
{  int value;
   unsigned char result[]=" ";
 

   set_tris_b(0); //set port b as output
   setup_adc_ports(ALL_ANALOG);
   setup_adc(ADC_CLOCK_INTERNAL);
   set_adc_channel(0);
 
   for(;;)
   {   lcd_init();
        value=Read_ADC();
        sprintf(result,"%d",value);
        lcd_putc(result);
        delay_ms(250);



}
}


with the header
Code:

#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES HS                       //High speed Osc (> 4mhz)
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOOSCSEN                 //Oscillator switching is disabled, main oscillator is source
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES BORV20                   //Brownout reset at 2.0V
#FUSES NOPUT                    //No Power Up Timer
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES LVP                      //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOCPD                    //No EE protection
#FUSES NOCPB                    //No Boot Block code protection
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads

#use delay(clock=10000000)


Actually the header part does not mean anything at all to me!

This code actually compiles without any errors but whenever I load it to Proteus 6.0 18F452, the program (ISIS) crashes.

The connections are very basic too:
I am using Port B ( all 7 pins ) to drive the LCD and from Port A0, I am sending a sine wave.
( I didn't forget to uncomment the line that switches from Port B to Port D)

Apart from this, I could not figure out how the LCD is driven by the PIC.
I checked out some sample code but none of them actually specifies input/output directions for the ports.

Moreover, in the PIC wizard, the port specification part asks me the I/O connections but that doesn't correspond to anything in the code tab.
Is there something wrong with my compiler or is it just normal?


For the moment, that's all I wanted to know about

Thank you very much in advance






Laughing Laughing
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Mar 15, 2007 3:02 pm     Reply with quote

This is not a Proteus board.

But, with regard to your C program, I see a few problems.

Quote:
unsigned char result[]=" ";

This array can only hold a string that consists of one character
(plus the zero byte at the end, which acts as the string terminator).

Then down here in your code, you are writing up to 3 ASCII characters
to your array. It can only hold one. You strongly risk destroying
any variables that the compiler has allocated in the RAM addresses
just after your array.
Quote:
sprintf(result,"%d",value);

You need to increase the size of the array.


Also you've got other things in there like enabling LVP mode.
I don't know what Proteus does with that, but with real hardware
you risk a lockup. Change it to NOLVP.
mskala



Joined: 06 Mar 2007
Posts: 100
Location: Massachusetts, USA

View user's profile Send private message

PostPosted: Thu Mar 15, 2007 6:47 pm     Reply with quote

I've just done this recently. I was using ports D and E, but will work with any. From your pin definitions, you are using the Motorola M68-type format. If you need specs for this type of parallel interface, google it.

I was using 8 bits, but 4 bits is similar, you will need to use 2 cycles of the E bit rather than 1.

Here are the segments of code:

#define VFD_RW PIN_E0
#define VFD_E PIN_E1
#define VFD_RS PIN_E2

void vfd_w_inst(int8 value) // write instruction
{
output_low(VFD_RS);
output_low(VFD_RW);
output_high(VFD_E);
output_d(value);
output_low(VFD_E);
}

void vfd_w_data(int8 value) // write data
{
output_high(VFD_RS);
output_low(VFD_RW);
output_high(VFD_E);
output_d(value);
output_low(VFD_E);
}

void initdisp() // initialize display after power up
{
vfd_w_inst(0x3c); // function set, necessary first command
delay_us(2);
vfd_w_inst(0x0c); // display on, no cursor, no blink
delay_us(2);
vfd_w_inst(0x01); // clear display
delay_us(2);
vfd_w_inst(0x03); // cursor home
delay_us(2);
vfd_w_inst(0x06); // entry mode set
delay_us(2);
}

void displaynumber2(int8 num) // displays 8-bit number in decimal always 3 dig
{
int8 copy,a,b,c;

a=num/100;
copy=num-(a*100);
b=copy/10;
c=copy-(b*10);
vfd_w_data(a+48);
vfd_w_data(b+48);
vfd_w_data(c+48);
}

----
anywhere after initializing you can send characters as:
vfd_w_data('V');
vfd_w_data('a');
vfd_w_data('l');
vfd_w_data('u');
vfd_w_data('e');
vfd_w_data('=');
vfd_w_data(' ');


Good luck
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