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

[solved] PIC18f26k22 Timeout? Limited execution time?

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



Joined: 17 Jun 2013
Posts: 18

View user's profile Send private message

[solved] PIC18f26k22 Timeout? Limited execution time?
PostPosted: Thu Oct 10, 2013 4:03 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Oct 10, 2013 4:16 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Oct 10, 2013 4:46 am     Reply with quote

Embarassed So simple, embarrassing Smile

Thank You, great forum.
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Thu Oct 10, 2013 5:22 am     Reply with quote

zzeroo wrote:
Embarassed So simple, embarrassing Smile


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: 19346

View user's profile Send private message

PostPosted: Thu Oct 10, 2013 7:36 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Oct 10, 2013 7:44 am     Reply with quote

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.
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