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 support@ccsinfo.com

pic16f1938 internal oscillator -lcd problem[Solved]

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



Joined: 21 Aug 2012
Posts: 47

View user's profile Send private message

pic16f1938 internal oscillator -lcd problem[Solved]
PostPosted: Fri Nov 30, 2012 5:35 pm     Reply with quote

Hi. I want to show the message in 2*16 lcds with pic16f1938 with internal oscillator. But when I write the lcd register defined in ccs the pic does not work. For example:

This code is not work
Code:

#include <16F1938.h>
#FUSES INTRC_IO                   
#use delay(clock=4m)               

#define use_portB_lcd TRUE
#define LCD_ENABLE_PIN PIN_B3
#define LCD_RS_PIN PIN_B1
#define LCD_RW_PIN PIN_B2
#define lcd_data4 pin_b4
#define lcd_data5 pin_b5
#define lcd_data6 pin_b6
#define lcd_data7 pin_b7
#define LCD_TYPE 2
#include <lcd.c>

//==========================================
void main()
{
lcd_init();

while(true)
  {
   lcd_gotoxy(1,1);
   printf(lcd_putc,"Hi");

   output_toggle(pin_c2);
   delay_ms(500);
  }

}


But this code is work:
Code:

#include <16F1938.h>
#FUSES INTRC_IO                   
#use delay(clock=4000000)           

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

while(true)
  {
   output_toggle(pin_c2);
   delay_ms(500);
  }

}

One thing I have to say that all codes will work on Proteus.

This is my circuit:

Where is the problem?

Thanks


Last edited by Mahdi on Sun Dec 02, 2012 6:18 am; edited 1 time in total
temtronic



Joined: 01 Jul 2010
Posts: 9174
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Nov 30, 2012 8:53 pm     Reply with quote

hints..
1) Proteus is NOT a 'good' simulator. If you wired up your circuit as shown in the Proteus schematic the LCD will never, ever work.

2) Most PIC I/O pins will serve several purposes and other 'peripherals' must be disabled. Typically I/O pins with ADC capability will be defaulted to ADC use, thus overriding basic I/O use.

3)How do you know program 2 works? Do you use an oscilloscope to see the output on C2? If not, put an LED (and correct resistor) on it to visually confirm proper operation.

4) It's better to use the 'flex_lcd.c' driver. Most here use it, I think.

5) Check the 'timing' setup for your LCD. Not all are the same.

6) You MUST call lcd_init() before sending the LCD any data. Think of lcd_init() as the 'key' that unlocks the door (the LCD module). You can't get in until it's unlocked.

hth
jay
Mahdi



Joined: 21 Aug 2012
Posts: 47

View user's profile Send private message

PostPosted: Sat Dec 01, 2012 2:13 am     Reply with quote

Quote:
3)How do you know program 2 works? Do you use an oscilloscope to see the output on C2? If not, put an LED (and correct resistor) on it to visually confirm proper operation.


i use the led.when i write the lcd define in ccs the lcd not flashes but when delete the lcd register the pic is work and led flashes properly

i test this code with pic16f877a and external osc it work properly.now my problem is with internal osc

I do not know what to do
Ttelmah



Joined: 11 Mar 2010
Posts: 19368

View user's profile Send private message

PostPosted: Sat Dec 01, 2012 7:59 am     Reply with quote

The define 'USE_PORTB_LCD', requires the LCD pins to be wired as:
B0 enable
B1 RS
B2 RW
B3 N/C
B4...B7 to the LCD D4 to D7 pins.

When this define is used, the individual pin defines are ignored.....

You have the N/C pin on B0, which won't work with this define.

Obviously on a real display, the lack of supply connections to the display will prevent it working. One of the dangers of Proteus.

Best Wishes
Mahdi



Joined: 21 Aug 2012
Posts: 47

View user's profile Send private message

PostPosted: Sat Dec 01, 2012 10:46 am     Reply with quote

Ttelmah wrote:
The define 'USE_PORTB_LCD', requires the LCD pins to be wired as:
B0 enable
B1 RS
B2 RW
B3 N/C
B4...B7 to the LCD D4 to D7 pins.

When this define is used, the individual pin defines are ignored.....

You have the N/C pin on B0, which won't work with this define.

Obviously on a real display, the lack of supply connections to the display will prevent it working. One of the dangers of Proteus.

Best Wishes


when i delete lcd_init(); and printf(lcd_putc,"Hi"); the led on pin_c2 start to blinking.

According to Ttelmah i connect lcd pin as standard mode

#define LCD_ENABLE_PIN PIN_b0
#define LCD_RS_PIN PIN_b1
#define LCD_RW_PIN PIN_b2
#define LCD_DATA4 PIN_b4
#define LCD_DATA5 PIN_b5
#define LCD_DATA6 PIN_b6
#define LCD_DATA7 PIN_b7

but its not work

this is my code

it work and the led start to blinking:


Code:
#include <16F1938.h>

#FUSES NOWDT                   
#FUSES INTRC_IO                 
#FUSES WDT_SW                   
#FUSES NOBROWNOUT               
#FUSES NOLVP                   

#use delay(int=4000000)


#include <lcd.c>


void main()
{



   while(TRUE)
   {
   
   output_toggle(pin_c2);
   delay_ms(300);


   }

}


its not work and the led not blinking:

Code:
#include <16F1938.h>

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES WDT_SW                   //No Watch Dog Timer, enabled in Software
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O

#use delay(int=4000000)

#include <lcd.c>


void main()
{

lcd_init();

   while(TRUE)
   {
   
   output_toggle(pin_c2);
   delay_ms(300);
   lcd_gotoxy(1,1);
printf(lcd_putc,"Hi");




   }

}


when i touch the pin_b7, the led become switch on and again when i touch the pin_b7 the led become switch off.in fact my finger play oscillator roll.
whats the reason of this event?
Mahdi



Joined: 21 Aug 2012
Posts: 47

View user's profile Send private message

PostPosted: Sun Dec 02, 2012 6:19 am     Reply with quote

i pull down the pin b7 and its work properly.thanks alot
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