Last active
August 29, 2015 14:10
-
-
Save neutronstriker/85b30f4578896404d1f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define SIPO PORTB | |
#define STB PB3 | |
#define SPIN PB4 | |
#define CLK PB5 | |
//Rememeber DDRB |= (1<<STB) | (1<<SPIN) | (1<<CLK); //must be done in main() so as set these pins as output. | |
void send_nibble(unsigned char x) //try to make this also inline if necessary | |
{ | |
x |= (1<<en); // set en pin as 1 | |
SIPO_send(x); //send the data through SIPO | |
SIPO |= (1<<STB); //after sending enable the STROBE so that data is now available on the data pins | |
_delay_ms(1); //give delay of 10ms for enable change CLK | |
SIPO &= ~(1<<STB);//clear the strobe now | |
x &= ~(1<<en); // now make the enable pin of lcd as 0 | |
SIPO_send(x); // again send new data in which only enable pin state of lcd is changed | |
SIPO |= (1<<STB); //again set the strobe | |
_delay_ms(1); //delay 10ms | |
SIPO &= ~(1<<STB); // clear the strobe | |
//to send a nibble 2 * 80us + 2 * 1ms = 2.16ms total delay | |
} | |
void lcd_cmd(unsigned char var) | |
{ | |
unsigned char x; | |
//send higher nibble | |
x = 0xf0 & var; //get higher nibble into x | |
x &= ~(1<<rs); //set the rs pin as 0 | |
send_nibble(x); //enable pin clocking mechanism is contained in nibble fucntion | |
//now send lower nibble | |
x = 0xf0 & (var<<4); // now repeat same process for lower nibble | |
x &= ~(1<<rs); | |
send_nibble(x); | |
//to send a cmd or data byte delay is 2 * 2.16ms = 4.32ms | |
//so data rate is 1/4.32ms = 231 char's /second ; good enough for our display | |
} | |
void lcd_data(unsigned char var) | |
{ | |
unsigned char x; | |
//send higher nibble | |
x = 0xf0 & var; | |
x |= (1<<rs); | |
send_nibble(x); | |
//now send lower nibble | |
x = 0xf0 & (var<<4); | |
x |= (1<<rs); | |
send_nibble(x); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment