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

RTOS with LCD for 16F887, LCD shows nothing

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



Joined: 09 Jan 2012
Posts: 45

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

RTOS with LCD for 16F887, LCD shows nothing
PostPosted: Sat Feb 08, 2020 2:39 pm     Reply with quote

Hello,
I am trying to learn RTOS with pic 16f887 and i want to display some
characters on the LCD, but the LCD won't show anything. Below is the code:
Code:

#include <16F887.h>
#device ADC=10                   
#use delay(clock = 4000000)
#include <Flex_LCD420.c>
#fuses NOMCLR, NOBROWNOUT, NOLVP, INTRC_IO
#use fast_io(C)
#use rtos(timer = 0, minor_cycle = 50ms)

#task(rate = 250ms, max = 50ms)     // 1st RTOS task (executed every 250ms)
void led1(){
  output_toggle(PIN_C4);
}

#task(rate = 500ms, max = 50ms)     // 2nd RTOS task (executed every 500ms)
void led2(){
  output_toggle(PIN_C5);
}

#task(rate = 750ms, max = 50ms)     // 3rd RTOS task (executed every 750ms)
void led3(){
  output_toggle(PIN_C6);
}

#task(rate = 1000ms, max = 50ms)    // 4th RTOS task (executed every 1000ms)
void led4(){
  output_toggle(PIN_C7);
}

#task(rate = 1250ms, max = 50ms)    // 5th RTOS task (executed every 1250ms)
void led5(){
   output_toggle(PIN_D1);
}

void main()
{
   lcd_init();
   setup_oscillator(OSC_4MHZ);      // Set the internal oscillator to 4MHz
   output_C(0);                     // All PORTC register pins are zeros
   set_tris_C(0);
   printf(lcd_putc,"RTOS Test");
   delay_ms(1000);
   rtos_run();
 
}
temtronic



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

View user's profile Send private message

PostPosted: Sat Feb 08, 2020 3:37 pm     Reply with quote

Does the LCD module function properly without the RTOS code ?
IE, the classic 'Hello World" program run ??
You should post which 'LCD' you're using.
Have to confirmed the wiring from PIC to LCD module IS the same as the default in the driver ?
Does the PIC actually run the '1Hz LED' program ?

I know it's not the driver as I use it and 4x20 LCD modules for past few years !
Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Sun Feb 09, 2020 1:19 am     Reply with quote

General comment.
Always configure the chip _before_ loading things.
So:
Code:

#include <16F887.h>
#device ADC=10   
#fuses NOMCLR, NOBROWNOUT, NOLVP, INTRC_IO               
#use delay(clock = 4000000)
//First configure the chip

#use fast_io(C)
#use rtos(timer = 0, minor_cycle = 50ms)
//Now setup the port and RTOS

#include <Flex_LCD420.c>
//Next include the LCD & any other code

//Then the rest of the program.

Historically you had to do this. The compiler now is more flexible on
letting things be done out of order, but it is still 'better' to work in this
order.

Now I repeat Temtronic's questions. Always get things working one
step at a time. Does the chip run and talk to the LCD?. There is no point
in starting trying to use the RTOS, until you have got the chip actually
working first. Test your LCD is working first.

Then a general comment. Have you got current limiting resistors on
the LED's?. These are required (not optional), and if missing or too small
will physically stop the chip running.

Your RTOS code posted will work. If it doesn't flash the LED's something
is wrong in the chip connections or the code to make the chip work,
not with the RTOS....
PrinceNai



Joined: 31 Oct 2016
Posts: 479
Location: Montenegro

View user's profile Send private message

PostPosted: Sun Feb 09, 2020 5:30 am     Reply with quote

Does the LCD turn on when you apply the power? You can see something changes on the LCD when you do it. I had some modules with + and - terminals reversed. The other thing I can think of is the contrast, maybe it works, but you just can't see it. And the last: you do use 5V power supply? On 3,3V those things mostly don't work. You haven't mentioned the LED's. Do they work as expected?

Samo
colesha



Joined: 09 Jan 2012
Posts: 45

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

PostPosted: Sun Feb 09, 2020 7:06 am     Reply with quote

Sorry for the delay in response,

Sorry i didn't mention, I am running it on Proteus. The LCD displays well when i load a different code without the rtos.
The LEDs are working perfectly well as per the task assignment. I even tried using the 2x16 LCD but still the same. When i try to do a debug in Proteus, the code responsible for the display is skipped and goes directly to the rtos_run() line.


I have rechecked the code and i tried eliminating some lines below the LCD_init() and i found out that
Code:

setup_oscillator(OSC_4MHZ);    // Set the internal oscillator to 4MHz

was the issue. The new code is this:
Code:

#include <16F887.h>
#device ADC=10   
#fuses NOMCLR, NOBROWNOUT, NOLVP, INTRC_IO               
#use delay(clock = 4000000)
#use fast_io(C)
#use rtos(timer = 0, minor_cycle = 50ms)
#include <Flex_LCD420.c>

#task(rate = 250ms, max = 50ms)     // 1st RTOS task (executed every 250ms)
void led1(){
  output_toggle(PIN_C4);
}

#task(rate = 500ms, max = 50ms)     // 2nd RTOS task (executed every 500ms)
void led2(){
  output_toggle(PIN_C5);
}

#task(rate = 750ms, max = 50ms)     // 3rd RTOS task (executed every 750ms)
void led3(){
  output_toggle(PIN_C6);
}

#task(rate = 1000ms, max = 50ms)    // 4th RTOS task (executed every 1000ms)
void led4(){
  output_toggle(PIN_C7);
}

#task(rate = 1250ms, max = 50ms)    // 5th RTOS task (executed every 1250ms)
void led5(){
   output_toggle(PIN_D1);
}

void main()
{
   lcd_init();
   [b]/*setup_oscillator(OSC_4MHZ);      // Set the internal oscillator to 4MHz*/[/b]
   output_C(0);                     // All PORTC register pins are zeros
   set_tris_C(0);
   printf(lcd_putc,"RTOS Test");
   delay_ms(1000);
   rtos_run();
 
}


The question is if i eliminate the setting of of the setup_oscillator(OSC_4MHZ) in the main, will it have any adverse effect on the performance?

Thanks for the responses, all were helpful.
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Sun Feb 09, 2020 8:00 am     Reply with quote

Forget Proteus.
Read the 'sticky' at the top of the forum.
Proteus gives significant problems when you try to do anything at all
'complex' in terms of program flow.

Understand. It does not reliably work.

Change your clock settings to:
Code:

#include <16F887.h>
#device ADC=10   
#fuses NOMCLR, NOBROWNOUT, NOLVP, INTRC_IO               
#use delay(INTERNAL= 4000000)
#use fast_io(C)
#use rtos(timer = 0, minor_cycle = 50ms)


This ensures the code does configure the oscillator to 4MHz.
The setup_oscillator is then not needed.
temtronic



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

View user's profile Send private message

PostPosted: Sun Feb 09, 2020 8:35 am     Reply with quote

well NOW we KNOW the problem.....
Proteus....
it's been busted, broke, nonfunctional for years......
colesha



Joined: 09 Jan 2012
Posts: 45

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

PostPosted: Mon Feb 10, 2020 11:31 am     Reply with quote

Thanks very much for the advice.
Let me purchase the components and set it up and forget about Proteu.s
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