I have this microcontroler with this LCD(DEM16216) mounted on it which I cannot initialize.
Only 4 of the pins are connected, thus it runs in a 4 bit mode (I think?). I found the datasheet for it (DEM16216) , which gives an step by step guide on how to do it, but for some reason it does not work for me...
Could someone tell me why this isn't working for me?
This is the datasheet for my LCD.
The one my teacher recommended was this one.
Complete code can be downloaded from [code]http://speedy.sh/vZJby/LCD-init-code.zip[/code]
init
is performed outside of a superloop, while command is performed inside a superloop.
Could anyone explain why this isn't working?
screen.c
#include"screen.h"
void nibble_value(INT8U binary_value)
{
if((binary_value & 0b00001000) == 8) //DB7
GPIO_PORTB_DATA_R |= (0b00100000);
else
GPIO_PORTB_DATA_R &= ~(0b00100000);
if((binary_value & 0b00000100) == 4) //DB6
GPIO_PORTB_DATA_R |= (0b00010000);
else
GPIO_PORTB_DATA_R &= ~(0b00010000);
if((binary_value & 0b00000010) == 2) //DB5
GPIO_PORTB_DATA_R |= (0b00001000);
else
GPIO_PORTB_DATA_R &= ~(0b00001000);
if((binary_value & 0b00000001) == 1) // DB4
GPIO_PORTB_DATA_R |= (0b00000100);
else
GPIO_PORTB_DATA_R &= ~(0b00000100);
}
void enable_pin (int a)
{
if (a)
{
GPIO_PORTB_DATA_R |= (0b01000000); //Disables "enable "pin
redLed(ON); //Debug
}
else{
GPIO_PORTB_DATA_R &= ~(0b01000000); // Enables "enable" pin
redLed(OFF); //debug
}
}
void screen_init( void )
{
//POwer on
//MILLISEC(100);
enable_pin(OFF);
yellowLed(ON);
greenLed(OFF);
redLed(OFF);
for(i=0; i<10000000; i++);
yellowLed(OFF);
redLed(ON);
// Special case Function set
//----------------------------------------------------------------//
// MILLISEC(1); // 1 ms delay
nibble_value(0b00000011); // DB5 = 1, DB4 = 1
enable_pin(ON); // enable pin on
enable_pin(OFF); // enable pin off
// MILLISEC(15); // 5 ms delay
for(i=0; i<10000000; i++);
GPIO_PORTF_DATA_R ^= 0x01;
// MILLISEC(1); // 1 ms delay
nibble_value(0b00000011); // DB5 = 1, DB4 = 1
enable_pin(ON); // enable pin on
enable_pin(OFF); // Enable pin off
// MILLISEC(15); // 5 ms delay
for(i=0; i<10000000; i++);
GPIO_PORTF_DATA_R ^= 0x01;
// MILLISEC(1); // 1 ms delay
nibble_value(0b00000011); // DB5 = 1, DB4 = 1
enable_pin(ON); // enable pin on
enable_pin(OFF); // enable pin off
// MILLISEC(5); // 5 ms delay
for(i=0; i<10000000; i++);
GPIO_PORTF_DATA_R ^= 0x01;
//-----------------------------------------------------------------//
//initial Function set
//-----------------------------------------------------------------//
// MILLISEC(1); // 1 ms delay
nibble_value(0b00000010); // 0x02 = 0b00000010 => DB5 = 1
enable_pin(ON); // enable pin on
enable_pin(OFF); // enable pin = off
// MILLISEC(5); // 5 ms delay
for(i=0; i<10000000; i++);
GPIO_PORTF_DATA_R ^= 0x01;
//----------------------------------------------------------------//
//Function set
//----------------------------------------------------------------//
// MILLISEC(1); // 1 ms delay
nibble_value(0b00000010); // 0x02 = 0b00000010 => DB5 = 1
enable_pin(ON); // enable pin on
enable_pin(OFF); // enable pin = off
// MILLISEC(5); // 5 ms delay
for(i=0; i<10000000; i++);
GPIO_PORTF_DATA_R ^= 0x01;
// MILLISEC(1); // 1 ms delay
nibble_value(0b00001000); // 0x8 = 0b00001000 n = 1 and f = 0 => DB7 = 1
enable_pin(ON); // enable pin on
enable_pin(OFF); // enable pin = off
// MILLISEC(5); // 5 ms delay
for(i=0; i<10000000; i++);
GPIO_PORTF_DATA_R ^= 0x01;
//----------------------------------------------------------------//
//Display On/Off
//----------------------------------------------------------------//
// MILLISEC(1); // delay = 1 ms
nibble_value(0x00); // ZERO
enable_pin(ON); // enable pin on
enable_pin(OFF); // enable pin = off
// MILLISEC(5); // delay 5 ms
for(i=0; i<10000000; i++);
GPIO_PORTF_DATA_R ^= 0x01;
// MILLISEC(1); // delay = 1 ms
nibble_value(0b00001000); // DB7 = 1 => display off
enable_pin(ON); // enable pin on
enable_pin(OFF); // enable pin = off
// MILLISEC(5); // delay = 5 ms
for(i=0; i<10000000; i++);
GPIO_PORTF_DATA_R ^= 0x01;
//---------------------------------------------------------------//
//Clear Display
//---------------------------------------------------------------//
// MILLISEC(1); // delay = 1 ms
nibble_value(0b00000000); // Zero
enable_pin(ON); // enable pin on
enable_pin(OFF); // Enable pin = off
// MILLISEC(5); // Delay = 5 ms
for(i=0; i<10000000; i++);
GPIO_PORTF_DATA_R ^= 0x01;
// MILLISEC(1); // delay = 1 ms
nibble_value(0b00000001); // No configurable bits, CLEAR Display
enable_pin(ON); // enable pin on
enable_pin(OFF); // enable = off
// MILLISEC(5); // delay = 5 ms
for(i=0; i<10000000; i++);
GPIO_PORTF_DATA_R ^= 0x01;
//---------------------------------------------------------------//
//Entry Mode set
//---------------------------------------------------------------//
// MILLISEC(1); // delay = 1 ms
nibble_value(0b00000000); // Zero
enable_pin(ON); // enable pin on
enable_pin(OFF); // Enable pin = off
// MILLISEC(5); // Delay = 5 ms
for(i=0; i<10000000; i++);
GPIO_PORTF_DATA_R ^= 0x01;
// MILLISEC(1); // delay = 1 ms
nibble_value(0b00000110); // DB6 = 1, DB5 = 1 (increment by 1) , DB4 = 0 (No shift)
enable_pin(ON); // enable pin on
enable_pin(OFF); // enable = off
// MILLISEC(5); // delay = 5 ms
for(i=0; i<10000000; i++);
GPIO_PORTF_DATA_R ^= 0x01;
//---------------------------------------------------------------//
}
void command (void)
{
//Command
//---------------------------------------------------------------//
nibble_value(0b00000000); // Zero
enable_pin(ON); // enable pin on
enable_pin(OFF); // Enable pin off
for(i=0; i<100; i++);
//--------------------------------------------------------------//
//Command
//---------------------------------------------------------------//
nibble_value(0b00001111); // D = 1, C = 1 , B = 1 => display on, cursor on and blinking on..
enable_pin(ON); // enable pin on
enable_pin(OFF); // Enable pin off
for(i=0; i<100; i++);
//--------------------------------------------------------------//
}
Main.c
#include "lm3s6965.h"
#include "systick.h"
#include "gpio.h"
#include "emp_type.h"
#include "swtimers.h"
#include "LED.h"
#include "screen.h"
int main(void)
{
disable_global_int();
init_clk_system();
init_gpio();
systick_init();
enable_global_int();
screen_init();
INT16S alive_timer = MILLISEC(500);
while(1)
{
redLed(ON);
yellowLed(ON);
greenLed(ON);
while( !klik );
klik--;
if( ! --timer )
{
timer = MILLISEC( 500 );
GPIO_PORTF_DATA_R ^= 0x01;
}
}
}