Go Down

Topic: silly me!! need lcd help (Read 387 times) previous topic - next topic


well i went ahead and made a pcb and soldered an lcd , 16x2 , to it so basically all the wiring is set in stone
and lately ive been wanting to learn how to do things without using other peoples libraries just so that i may learn how things really work behind the curtains

okay like i said my wiring is set in stone so keep that in mind...

unfortunately  i never used an lcd before so i just counted how many connections i needed and stuck them all over the microcontroller

the wiring is:

Enable :                PINC5
ReadWrite :          PIND2
RegisterSelect       PIND3

DataLines 4 - 7      PortC Pins 4 - 1

and a pot from ground to 5v and wiper to the contrast pin

Code: [Select]

* DevBoardLCD.c
* Created: 8/12/2013 2:31:39 AM
*  Author: eddiea6987

#define F_CPU 16000000
#include <avr/io.h>
#include <util/delay.h>

#define enable PINC5 //when writting to lcd data is transfered only on the high to low transition
#define readWrite PIND2 //read write :low to write commands or high to read
#define registerSelect PIND3 //register select : low = commands : high = character

//PORTC    0 0 0 [ 0 0 0 0 ] 0
//the above shows my data lines on port c
void flipEnable(void);
void portCReset();
int main(void)

DDRD |= (1<<registerSelect | 1<<readWrite) ; //set controls to output since i will only be writing to them
DDRC = 0b11111111; //set all of port c to out put since its my data lines and enable pin

PORTC &= ~(1<<enable); //set enable low
PORTD &= ~(1<<readWrite | 1<<registerSelect); //set readwrite to low to write to lcd , and set register select to low to send command
_delay_ms(2000);//delay to let lcd  stabalize..probably too long of a delay but its ok

//send 3 commands of 0x30 to let the lcd start up properly in 8 bit mode  /////////
portCReset(); //make sure all ports on c are cleared

//PORTC    0 0 0 [ 0 0 1 1 ] 0
PORTC |= (1<<PINC1 | 1<<PINC2);//since my data lines dont correspond exactly to the 4 lower pins on port c, but rather pins 4-1  this is how i have to do it
//equivilant of 0x30

PORTC |= (1<<PINC2 | 1<<PINC1);  // do it again

PORTC |= 1<<PINC2 | 1<<PINC1 ; //and one more time

//PORTC    0 0 0 [ 1 0 0 0 ] 0      now set to 4 bit mode, these are the high bits of the byte
PORTC |= 1<<PINC2 ;

//PORTC    0 0 0 [ 1 0 0 0 ] 0
PORTC |= 1<<PINC4 | 1<<PINC3; //send command 1100 to set to two line mode and to enable display , these are the 4 lower bits
_delay_ms(2); // should be in 4 bit mode now...theoretiaclly


//test A
PORTD |= 1<<registerSelect; // set register select high to send character
        portCReset(); // let me clear the data lines just to be safe

//let me send capital "P" 01010000
// so the 4 high bits are 0101
//which on my ports c would be PORTC    0 0 0 [ 0 1 0 1 ] 0
PORTC |= 1<<PINC1 | 1<<PINC3 ;

    portCReset(); // since this clears the port , the data lines are now low and i can send the 4 lower bits which are 0's anyways
_delay_ms(5000); //just delaying to see if anything happens
// i get all black boxes on on the top line , which i read somewhere it means it is not initialized..


void portCReset()
PORTC = 0B00000000;

void flipEnable()
PORTC |= (1<<enable);//toggle the enable pin so that data can be transfgered on falling edge
PORTC &= ~(1<<enable);
portCReset(); // reset the data lines


I could print the Arduino logo on a box of cereal and sell it as "Arduin-O's"


And the question is?


PS I think you need some desoldering braid.


Go Up