View previous topic :: View next topic |
Author |
Message |
zzeroo
Joined: 17 Jun 2013 Posts: 18
|
[solved] PIC18f26k22 Timeout? Limited execution time? |
Posted: Thu Oct 10, 2013 4:03 am |
|
|
Hello,
I've found a strange behavior and hope someone can me explain what's happen here.
For a new project I'm working at the moment I have to interface a PIC18f26k22 with a EA DOGM128-6 128x64 LCD. The display works fine, here is a simplified version packed in main().
First things first, my header part Code: |
// Device header
#include <18f26k22.h>
// MCU configuration
#fuses XT
#fuses NOWDT //No Watch Dog Timer
#fuses NOPROTECT //Code not protected from reading
#fuses BROWNOUT //brownout reset
#fuses PUT //Power Up Timer an
#fuses NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
//#fuses MCLR
#use delay(clock=20MHz) |
The problem occurs if I uncomment the // DISPLAY FILL COMMANDS commands in the following code. All following commands are ignored/ not executed then.
Code: |
void main() {
dogm128_Init();
// DISPLAY FILL COMMANDS
// uncomment this stops execution of display
/*
unsigned int dispram[1024], d = 0;
for (d = 0; d < 1024; d++)
dispram[d] = 0x00;
*/
// fills LCD with black pixel, works fine if // DISPLAY FILL COMMANDS is commented
int8 page;
for (page = 0; page < 8; page++) {
dogm_send_command(0xB0 + page); //Set page address to <page>
dogm_send_command(0x10 + 0); //Set column address to 0 (4 MSBs)
dogm_send_command(0x00 + 0); //Set column address to 0 (4 LSBs)
int8 column;
for (column = 0; column < 128; column++)
dogm_send_display_data(0xFF);
}
}
|
It looks like the PIC can't execute this simple command, what's happen here? Is there a time window or something similar?
Last edited by zzeroo on Thu Oct 10, 2013 5:20 am; edited 1 time in total |
|
|
oxo
Joined: 13 Nov 2012 Posts: 219 Location: France
|
|
Posted: Thu Oct 10, 2013 4:16 am |
|
|
You have an 8 bit index into a 1k array. d will always be less than 1024, so never exits from loop. |
|
|
zzeroo
Joined: 17 Jun 2013 Posts: 18
|
|
Posted: Thu Oct 10, 2013 4:46 am |
|
|
So simple, embarrassing
Thank You, great forum. |
|
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Thu Oct 10, 2013 5:22 am |
|
|
zzeroo wrote: | So simple, embarrassing
|
Also you declare the array and index, d, after the code, dogm128_Init(); this may not work, or may be unreliable. This is C and such in-code declarations are not normally allowed, though CCS sort of supports them. That would be OK in C++ or C#, but not C. Declare variables at the start of a block, i.e. immediately after the opening brace { (which includes at the start of a routine), or globally.
Another thing is that as your main() doesn't have a infinite loop, it will end. The compiler puts in an unseen sleep after main. This means that even if the rest of the code works, some of your output may well be lost if its still outputting when main() ends. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19535
|
|
Posted: Thu Oct 10, 2013 7:36 am |
|
|
As another comment, use provided functions....
memset(dispram, 0, sizeof(dispram));
will fill the array with zero characters, and do it faster than the for loop (only a little).
Best Wishes |
|
|
zzeroo
Joined: 17 Jun 2013 Posts: 18
|
|
Posted: Thu Oct 10, 2013 7:44 am |
|
|
Ttelmah wrote: |
memset(dispram, 0, sizeof(dispram));
|
Faster and shorter thanks Ttelmah.
@RF_Developer: That's clear. This was just a example to show my question. And not a "look my nifty skills!"-thing. |
|
|
|