Discussion in "Project Help" started by    PsySc0rpi0n    Nov 27, 2014.
Wed Jan 14 2015, 11:44 pm
#31


Yes it does, indeed. But I have allocated those variables into specific memory locations like:

__data __at (0x10) unsigned short var1;
__data __at (0x11) unsigned char var2;


So, because a short int takes 2 bytes, it would be using 0x10 and 0x11 and therefore, overlapping var2 at 0x11.

PsySc0rpi0n


Right ..that makes sense
So the obvious question is..
why are you locating your data at fixed locations ?
Thu Jan 15 2015, 03:52 am
#32
It's just a matter of controlling what was going on during the code debugging with each variable!
Thu Jan 15 2015, 10:27 am
#33
If you are concerned about debugging only then I think you can open the map file which lists all your symbols in the program and their addresses. so you never have to fix location for your variables.
Fri Jan 16 2015, 12:38 am
#34


If you are concerned about debugging only then I think you can open the map file which lists all your symbols in the program and their addresses. so you never have to fix location for your variables.

ajay_bhargav



Yes, indeed, and I know about that but as I don't have yet enough knowledge to dig into those files, It's kinda useless to me to check them. And it's faster when I run the code, to have right next to my eyes, the value of each variable in the memory map the simulator I'm using has.

Best regards.
PsySc0rpi0n
Sun Jan 18 2015, 11:30 am
#35
It's obviously a personal choice. Digging into map and listing files need extra efforts. For debugging your method sounds fine.
Mon Jan 19 2015, 01:53 am
#36
But it's a way to debug to consider to the future and let the compiler to manage memory by itself!
Tue Jan 20 2015, 10:06 am
#37
I agree!
Mon Feb 09 2015, 05:06 pm
#38
Hello once more...

I'm really struggling to make my hardware work with my code.

I've tried a small ASM code from a friend of mine and it worked perfectly but with my C code it's not working... I think I can't even init the LCD...

Can you help me break down my code and figure out where the problem is?

#include "reg_uC89C4xx.h"

#define RS P3_7
#define RW P3_6
#define E  P3_5

#define BF P1_7

#define CLR_E   (E  = 0)
#define SETB_E  (E  = 1)
#define SETB_RS (RS = 1)
#define CLR_RS  (RS = 0)
#define SETB_RW (RW = 1)
#define CLR_RW  (RW = 0)
#define SETB_BF (BF = 1)
#define CLR_BF  (BF = 0)

void send_string  (unsigned char *string);
void busy_f_check (void);
void e_delay      ();
void send_cmd     (unsigned char cmd);
void send_data    (unsigned char data);
void init_LCD     ();

void send_string (unsigned char *string){ /*send a string to the LCD DDRAM*/
    while (*string){
        send_data (*string);
        ++string;
    }
}

void busy_f_check (void){
    SETB_BF;
    SETB_E;
    CLR_RS;
    SETB_RW;
    while (BF){
        CLR_E;
        e_delay ();
        SETB_E;
    }
}

void e_delay (){
    TMOD = 0x01;
    TH0  = 0xFF;
    TL0  = 0xFA;
    TR0  = 0x01;
    while (!TF0);
    TR0  = 0x00;
    TF0  = 0x00;
}

void send_cmd (unsigned char cmd){
    busy_f_check ();
    P1 = cmd;
    CLR_RS;
    CLR_RW;
    CLR_E;
    e_delay ();
    SETB_E;
}

void send_data (unsigned char data){ /*send some data/char to LCD*/
    busy_f_check ();
    P1 = data;
    SETB_RS;
    CLR_RW;
    CLR_E;
    e_delay ();
    SETB_E;
}

void init_LCD (){
    send_cmd (0x38);/*configure LCD with 2 lines, 5x7 matrix*/
    send_cmd (0x0F);/*Display ON, Cursor Blinking, Cursor ON*/
    send_cmd (0x01);/*Clear display*/
    send_cmd (0x06);/*Increment cursor mode*/
}

void main (void) {
    SP = 0x40;
    init_LCD    ();
    send_cmd    (0x85);
    send_string ("HELLO");
    send_data   ('A');
    while (1);
}
Tue Feb 10 2015, 10:07 am
#39
there can be two main reasons:
1. Power up self init delay
2. Command/Data execution delay

So in init_LCD function add a small delay at start. and increase e_delay a little more. At start Keep it high and see if lcd works and then lower down e_delay bit by bit.
Tue Feb 10 2015, 02:47 pm
#40
Ok. I'll try that. Let me just say that LCD is working flawlessly with a small ASM code a friend of mine gave me. So I can assume that all wiring is OK. Problem is really in software... What should be a reasonable value for e_delay function? I have done it with about 5uS that is about 7 or 8 times more than what they say in dataset it needs for tW.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

KevinTab
Sun Apr 28 2024, 05:35 am
Tumergix
Sun Apr 28 2024, 12:59 am
StevenDrulk
Sat Apr 27 2024, 08:47 pm
StephenHauct
Sat Apr 27 2024, 09:38 am
Adamsaf
Sat Apr 27 2024, 07:12 am
Robertphype
Sat Apr 27 2024, 12:23 am
ktaletrryp
Fri Apr 26 2024, 10:55 pm
Robertrip
Fri Apr 26 2024, 11:20 am