Jonnhybob
06-18-02, 03:25 PM
Hello!
I'm trying to use a DSP-0803-MINI to control a LCD but my C programs just don't seem to work. It would be nice if someone could send me a program that make something (anything!!) appear on a LCD screen so I could find where I'm doing wrong.
thanks you !!
Jonnhybob
P.S. :
If someone is even nicer and has enough time to spend,
my program is below :
/*------------------------------------------------------*
Nom du programme : LCD.c
Application:Laboratory Status Monitor
Target Board: NMIN-0803-MINI.
*------------------------------------------------------*/
/* PORT E General Purpose Input/Output (GPIOE) */
#define pepur (short *)0x0ff0 //; Port E pull-up reg.
#define pedr (short *)0x0ff1 //; Port E data reg.
#define peddr (short *)0x0ff2 //; Port E data direction reg.
#define peper (short *)0x0ff3 //; Port E peripheral reg.
#define peiar (short *)0x0ff4 //; Port E interrupt assert reg.
#define peienr (short *)0x0ff5 //; Port E interrupt enable reg.
#define peipolr (short *)0x0ff6 //; Port E interrupt polarity reg.
#define peipr (short *)0x0ff7 //; Port E interrupt pending reg.
#define peiesr (short *)0x0ff8 //; Port E interrupt edge sensitive reg.
/* PORT A General Purpose Input/Output (GPIOA) */
#define papur (short *)0x0fb0 //; Port A pull-up reg.
#define padr (short *)0x0fb1 //; Port A data reg.
#define paddr (short *)0x0fb2 //; Port A data direction reg.
#define paper (short *)0x0fb3 //; Port A peripheral reg.
#define paiar (short *)0x0fb4 //; Port A interrupt assert reg.
#define paienr (short *)0x0fb5 //; Port A interrupt enable reg.
#define paipolr (short *)0x0fb6 //; Port A interrupt polarity reg.
#define paipr (short *)0x0fb7 //; Port A interrupt pending reg.
#define paiesr (short *)0x0fb8 //; Port A interrupt edge sensitive reg.
/* LCD pinout : pedr4 = Enable ; pedr5 = R/W ; pedr6 = RS ; padr = DATA;*/
#define LCD_E1 *pedr = *pedr|0x0010 //LCD Enable ON
#define LCD_E0 *pedr = *pedr&0x00ef //LCD Enable OFF
#define LCD_RW1 *pedr = *pedr|0x0020 //LCD R/W = 1 (read)
#define LCD_RW0 *pedr = *pedr&0x00df //LCD R/W = 0 (write)
#define LCD_RS1 *pedr = *pedr|0x0040 //LCD RS = 1 (data)
#define LCD_RS0 *pedr = *pedr&0x00bf //LCD RS = 0 (control)
/* Functions */
void init(void); //initialise port A & E
void delay(int); //pause
void LCD_BUSY(void); //Wait until busy flag = 0
void LCD_INIT(void); //Initialise LCD
void LCD_CHR(int); //Send data to LCD
void LCD_SET(int); //Send command to LCD
int LCD_STATUS(void); //Check LCD command status
// -----------------MAIN --------------------------------------------------
// For now i'm just tring to make OK appear on the screen
void main(void)
{
delay(0xffff);
init();
LCD_INIT();
LCD_CHR(0x004f); //send an 'O'
LCD_CHR(0x004b); //send a 'K'
while(1);
}
// ------- LCD_INIT -------------------------------
void LCD_INIT(void)
{
delay(0xffff);
LCD_SET(0x0038);
delay(0xffff);
LCD_SET(0x0038);
delay(0xffff);
LCD_SET(0x0038); // function set, 5x7, 2lines
delay(0xffff);
LCD_SET(0x0008); //display off
LCD_SET(0x0006); //entry mode set
LCD_SET(0x000f); //display ON
LCD_SET(0x0001); //clear display
LCD_SET(0x0002); //cursor = home
}
// ------ Initialise port A & E --------
void init( void )
{
*peiar = 0x0000;
*peienr = 0x0000;
*peipolr = 0x0000;
*peiesr = 0x0000;
*peper = 0x0000;
*paiar = 0x0000;
*paienr = 0x0000;
*paipolr = 0x0000;
*paiesr = 0x0000;
*paper = 0x0000;
/* fix A as input and E as output */
*peddr = 0x00ff;
*paddr = 0x0000;
// Set control , read, and enable off
LCD_RS1;
LCD_RW1;
LCD_E0;
}
// -----------------delay(X) -------------------
// Forces a pause, length 3*X
void delay(int X)
{
int i;
for( i = 0; i < X; i++ )
{
asm(nop);
asm(nop);
asm(nop);
}
}
//--------------------- LCD_BUSY------------------------
// Wait until busy flag = 0
void LCD_BUSY(void)
{
while ((LCD_STATUS()&0x0080)==0x0001);
}
//-----------------------LCD_STATUS-----------------------------
//Read the command registers
int LCD_STATUS(void)
{
int DATA;
LCD_RS0;
LCD_RW1;
*paddr = 0x0000;
delay(2);
LCD_E1;
delay(5);
DATA = *padr;
LCD_E0;
LCD_RS1;
return DATA;
}
//-------------------LCD_CHR---------------------------------------------
// Launch data to LCD
void LCD_CHR(int DATA)
{
LCD_BUSY();
LCD_RS1;
LCD_RW0;
delay(2);
LCD_E1;
*paddr = 0x00ff; // Set port A as output
*padr = DATA;
delay(5);
LCD_E0;
LCD_RW1;
*paddr = 0x0000;
}
//-------------LCD_SET----------------------------------------------------
// Lauch a command to LCD
void LCD_SET(int INS)
{
LCD_BUSY();
LCD_RS0;
LCD_RW0;
delay(2);
LCD_E1;
*paddr = 0x00ff; // Set port A as output
*padr = INS;
delay(5);
LCD_E0;
LCD_RW1;
*paddr = 0x0000;
LCD_RS1;
}
thanks you again !!
I'm trying to use a DSP-0803-MINI to control a LCD but my C programs just don't seem to work. It would be nice if someone could send me a program that make something (anything!!) appear on a LCD screen so I could find where I'm doing wrong.
thanks you !!
Jonnhybob
P.S. :
If someone is even nicer and has enough time to spend,
my program is below :
/*------------------------------------------------------*
Nom du programme : LCD.c
Application:Laboratory Status Monitor
Target Board: NMIN-0803-MINI.
*------------------------------------------------------*/
/* PORT E General Purpose Input/Output (GPIOE) */
#define pepur (short *)0x0ff0 //; Port E pull-up reg.
#define pedr (short *)0x0ff1 //; Port E data reg.
#define peddr (short *)0x0ff2 //; Port E data direction reg.
#define peper (short *)0x0ff3 //; Port E peripheral reg.
#define peiar (short *)0x0ff4 //; Port E interrupt assert reg.
#define peienr (short *)0x0ff5 //; Port E interrupt enable reg.
#define peipolr (short *)0x0ff6 //; Port E interrupt polarity reg.
#define peipr (short *)0x0ff7 //; Port E interrupt pending reg.
#define peiesr (short *)0x0ff8 //; Port E interrupt edge sensitive reg.
/* PORT A General Purpose Input/Output (GPIOA) */
#define papur (short *)0x0fb0 //; Port A pull-up reg.
#define padr (short *)0x0fb1 //; Port A data reg.
#define paddr (short *)0x0fb2 //; Port A data direction reg.
#define paper (short *)0x0fb3 //; Port A peripheral reg.
#define paiar (short *)0x0fb4 //; Port A interrupt assert reg.
#define paienr (short *)0x0fb5 //; Port A interrupt enable reg.
#define paipolr (short *)0x0fb6 //; Port A interrupt polarity reg.
#define paipr (short *)0x0fb7 //; Port A interrupt pending reg.
#define paiesr (short *)0x0fb8 //; Port A interrupt edge sensitive reg.
/* LCD pinout : pedr4 = Enable ; pedr5 = R/W ; pedr6 = RS ; padr = DATA;*/
#define LCD_E1 *pedr = *pedr|0x0010 //LCD Enable ON
#define LCD_E0 *pedr = *pedr&0x00ef //LCD Enable OFF
#define LCD_RW1 *pedr = *pedr|0x0020 //LCD R/W = 1 (read)
#define LCD_RW0 *pedr = *pedr&0x00df //LCD R/W = 0 (write)
#define LCD_RS1 *pedr = *pedr|0x0040 //LCD RS = 1 (data)
#define LCD_RS0 *pedr = *pedr&0x00bf //LCD RS = 0 (control)
/* Functions */
void init(void); //initialise port A & E
void delay(int); //pause
void LCD_BUSY(void); //Wait until busy flag = 0
void LCD_INIT(void); //Initialise LCD
void LCD_CHR(int); //Send data to LCD
void LCD_SET(int); //Send command to LCD
int LCD_STATUS(void); //Check LCD command status
// -----------------MAIN --------------------------------------------------
// For now i'm just tring to make OK appear on the screen
void main(void)
{
delay(0xffff);
init();
LCD_INIT();
LCD_CHR(0x004f); //send an 'O'
LCD_CHR(0x004b); //send a 'K'
while(1);
}
// ------- LCD_INIT -------------------------------
void LCD_INIT(void)
{
delay(0xffff);
LCD_SET(0x0038);
delay(0xffff);
LCD_SET(0x0038);
delay(0xffff);
LCD_SET(0x0038); // function set, 5x7, 2lines
delay(0xffff);
LCD_SET(0x0008); //display off
LCD_SET(0x0006); //entry mode set
LCD_SET(0x000f); //display ON
LCD_SET(0x0001); //clear display
LCD_SET(0x0002); //cursor = home
}
// ------ Initialise port A & E --------
void init( void )
{
*peiar = 0x0000;
*peienr = 0x0000;
*peipolr = 0x0000;
*peiesr = 0x0000;
*peper = 0x0000;
*paiar = 0x0000;
*paienr = 0x0000;
*paipolr = 0x0000;
*paiesr = 0x0000;
*paper = 0x0000;
/* fix A as input and E as output */
*peddr = 0x00ff;
*paddr = 0x0000;
// Set control , read, and enable off
LCD_RS1;
LCD_RW1;
LCD_E0;
}
// -----------------delay(X) -------------------
// Forces a pause, length 3*X
void delay(int X)
{
int i;
for( i = 0; i < X; i++ )
{
asm(nop);
asm(nop);
asm(nop);
}
}
//--------------------- LCD_BUSY------------------------
// Wait until busy flag = 0
void LCD_BUSY(void)
{
while ((LCD_STATUS()&0x0080)==0x0001);
}
//-----------------------LCD_STATUS-----------------------------
//Read the command registers
int LCD_STATUS(void)
{
int DATA;
LCD_RS0;
LCD_RW1;
*paddr = 0x0000;
delay(2);
LCD_E1;
delay(5);
DATA = *padr;
LCD_E0;
LCD_RS1;
return DATA;
}
//-------------------LCD_CHR---------------------------------------------
// Launch data to LCD
void LCD_CHR(int DATA)
{
LCD_BUSY();
LCD_RS1;
LCD_RW0;
delay(2);
LCD_E1;
*paddr = 0x00ff; // Set port A as output
*padr = DATA;
delay(5);
LCD_E0;
LCD_RW1;
*paddr = 0x0000;
}
//-------------LCD_SET----------------------------------------------------
// Lauch a command to LCD
void LCD_SET(int INS)
{
LCD_BUSY();
LCD_RS0;
LCD_RW0;
delay(2);
LCD_E1;
*paddr = 0x00ff; // Set port A as output
*padr = INS;
delay(5);
LCD_E0;
LCD_RW1;
*paddr = 0x0000;
LCD_RS1;
}
thanks you again !!