[ create a new paste ] login | about

Link: http://codepad.org/tP3Yhmvb    [ raw code | fork ]

Canopus - C, pasted on Jan 20:
 // LCD display 128x64 w ST7920 driver connection:
 // D0..D7 - PA0..7
 // E      - PC7
 // RS     - PC6
 // RST    - PC5
 // R/W    - PC4
 

 
 
#define F_CPU 8000000UL

#include <avr/io.h>
#include <stdlib.h>
#include <util/delay.h>
//#include <avr/pgmspace.h>
#include <avr/interrupt.h>

//#include "font5x5full.h"


#define E_PIN PC7
#define RS_PIN PC6
#define Reset_PIN PC5
#define RW_PIN PC4     

#define BUTTON (1<<PC2) // int0 pin

unsigned char read_busy_flag(void){
	unsigned char temp;
	PORTC &= ~(1 << RS_PIN);	
	PORTC |= (1<< RW_PIN);	//cteni
	PORTC |= (1 << E_PIN);
	_delay_us(1);
	temp=PINA;
	PORTC &= ~(1 << E_PIN);
	if(temp & 0x80)
		return 1;	//LCD is busy
	else
		return 0; 
} 


// this function sends instruction command to LCD
void lcd_instruction(uint8_t instruction)
{
	while(read_busy_flag())	//wait while LCD is busy
		;
	PORTC &= ~(1 << RS_PIN);	
	PORTC &= ~(1<< RW_PIN);	//zapis
	PORTC |= (1 << E_PIN);
	PORTA = instruction;
	_delay_us(10);
	PORTC &= ~(1 << E_PIN);
	_delay_us(5);
	
}

// this function sends data to LCD
void lcd_data(uint8_t data)
{
	while(read_busy_flag())	//wait while LCD is busy
		;
	PORTC |= (1 << RS_PIN);
	PORTC &= ~(1<< RW_PIN);	//zapis
	PORTC |= (1 << E_PIN);
	PORTA = data;
	_delay_us(10);
	PORTC &= ~(1 << E_PIN);
	_delay_us(5);
	
	
}

// this function initilizes LCD for graphic mode
void init_ST7920()
{
	PORTC|=(1<<Reset_PIN);
	_delay_ms(1);
	PORTC&=~(1<<Reset_PIN);
	_delay_ms(1);
	PORTC|=(1<<Reset_PIN);
	
	_delay_ms(50);
	lcd_instruction(0b00110000);  // function set	
	_delay_us(100);
	lcd_instruction(0b00110000);  // function set
	_delay_us(37);
	lcd_instruction(0b00001100);  // display ON
	_delay_us(100);
	lcd_instruction(0b00000001);  // display clear
	_delay_ms(10);
	lcd_instruction(0b00000110);  // entry mode set
	_delay_ms(1);
	lcd_instruction(0b00000010);  // kurzor na pocatecni pozici
	_delay_ms(1);
	lcd_instruction(0b00010100);	//cursor shift, display no shift
	
}

void LCD_Text(unsigned char radek, char* string)
{
 unsigned char temp;
 switch(radek){
  case 1: temp = 0x80;
   break;
  case 2: temp = 0x90;
   break;
  case 3: temp = 0x88;
   break;
  case 4: temp = 0x98;
   break;
  default: temp = 0x80;
   break;  
 }
 lcd_instruction(temp);
 while(*string){
  lcd_data(*string);
  string++;
 }   

}

// main functions
// programs starts here
int main(void)
{
	
	OSCCAL = 0xA8;      // calibrate RC oscillator to 8 MHz
	DDRA =  0b11111111; // port A set for output
	PORTA = 0b00000000; // and outputting nothing now
	
	DDRC =  0b11111011;	 //
	PORTC = 0b00000100;  //pullup enable

	init_ST7920();  // go init LCD display
	
// main loop
// this functions repeats itself over and over and over until something burns out :)
    for (;;)
	{   	
		LCD_Text(1,"  11111111111   ");
		LCD_Text(2,"  22222222222   ");
		LCD_Text(3,"  33333333333   ");
		LCD_Text(4,"  44444444444   ");
		
		_delay_ms(200);
		
	}		
}


Create a new paste based on this one


Comments: