@ -15,25 +15,29 @@ uint8_t lcd_frameupdate = 0;
uint8_t lcd_textx = 0 ;
uint8_t lcd_texty = 0 ;
void
LCD_Send ( uint8_t data )
// Prevent Double Initialization
unsigned short LCD_flag = 0 ;
void LCD_Send ( uint8_t data )
{
SPI_MasterTransfer ( data ) ;
}
void
LCD_Init ( void )
void LCD_Init ( void )
{
// Check if already initialized
if ( ! ( LCD_flag & 1 ) )
{
SPI_MasterInit ( ) ;
/* Set Register Select and Chip Select as Output */
DDRC | = ( 1 < < PC7 ) | ( 1 < < PC6 ) ;
// Set Register Select and Chip Select as Output
DDRC | = ( 1 < < PC7 ) | ( 1 < < PC6 ) ;
/* Backup Status Register and disable Interrupts */
// Backup Status Register and disable Interrupts
uint8_t sreg = SREG ;
cli ( ) ;
/* Starting Init Command Sequence */
// Starting Init Command Sequence
LCD_Command_Mode ;
LCD_Chip_Select ;
@ -52,7 +56,7 @@ LCD_Init (void)
LCD_Clear ( ) ;
/* Restore Status Register */
// Restore Status Register
SREG = sreg ;
// Initialize TWI for Backlight Control
@ -61,10 +65,12 @@ LCD_Init (void)
// Initialize Dataflash
dataflash_init ( ) ;
// Set UART Init Flag
LCD_flag = 1 ;
}
}
void
LCD_Clear ( void )
void LCD_Clear ( void )
{
uint8_t x = 0 , y = 0 ;
@ -77,18 +83,17 @@ LCD_Clear (void)
LCD_Update ( ) ;
}
void
LCD_Update ( void )
void LCD_Update ( void )
{
int8_t page = 7 ;
/* Backup Status Register and disable Interrupts */
// Backup Status Register and disable Interrupts
uint8_t sreg = SREG ;
cli ( ) ;
do
{
if ( lcd_frameupdate & ( 1 < < page ) )
if ( lcd_frameupdate & ( 1 < < page ) )
{
LCD_Chip_Select ;
LCD_Command_Mode ;
@ -104,17 +109,15 @@ LCD_Update (void)
LCD_Chip_Unselect ;
}
}
while ( page - - ) ;
} while ( page - - ) ;
lcd_frameupdate = 0 ;
/* Restore Status Register */
// Restore Status Register
SREG = sreg ;
}
void
LCD_DrawPixel ( uint8_t x , uint8_t y , uint8_t mode )
void LCD_DrawPixel ( uint8_t x , uint8_t y , uint8_t mode )
{
// Check if x and y are within display coordinates
if ( ( x < 128 ) & & ( y < 64 ) )
@ -145,8 +148,7 @@ LCD_DrawPixel (uint8_t x, uint8_t y, uint8_t mode)
}
}
void
LCD_DrawLine ( uint8_t x0 , uint8_t y0 , uint8_t x1 , uint8_t y1 , uint8_t mode )
void LCD_DrawLine ( uint8_t x0 , uint8_t y0 , uint8_t x1 , uint8_t y1 , uint8_t mode )
{
// look here: http://de.wikipedia.org/wiki/Bresenham-Algorithmus
int8_t dx = abs ( x1 - x0 ) ;
@ -179,8 +181,7 @@ LCD_DrawLine (uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t mode)
}
}
void
LCD_DrawCircle ( uint8_t x0 , uint8_t y0 , uint8_t radius , uint8_t mode )
void LCD_DrawCircle ( uint8_t x0 , uint8_t y0 , uint8_t radius , uint8_t mode )
{
// look here: http://de.wikipedia.org/wiki/Bresenham-Algorithmus
int8_t f = 1 - radius ;
@ -218,8 +219,7 @@ LCD_DrawCircle (uint8_t x0, uint8_t y0, uint8_t radius, uint8_t mode)
}
}
void
LCD_PutChar ( const char c )
void LCD_PutChar ( const char c )
{
// basic support for cr und new line
switch ( c )
@ -247,8 +247,7 @@ LCD_PutChar (const char c)
}
}
void
LCD_PutString ( const char * s )
void LCD_PutString ( const char * s )
{
// no empty strings allowed!
if ( * s )
@ -256,17 +255,15 @@ LCD_PutString (const char *s)
do
{
LCD_PutChar ( * s ) ;
}
while ( * ( + + s ) ) ;
} while ( * ( + + s ) ) ;
}
}
void
LCD_PutString_P ( PGM_P s )
void LCD_PutString_P ( PGM_P s )
{
while ( 1 )
while ( 1 )
{
unsigned char c = pgm_read_byte ( s ) ;
unsigned char c = pgm_read_byte ( s ) ;
s + + ;
if ( c = = ' \0 ' )
@ -276,15 +273,13 @@ LCD_PutString_P (PGM_P s)
}
}
void
LCD_GotoXY ( uint8_t x , uint8_t y )
void LCD_GotoXY ( uint8_t x , uint8_t y )
{
lcd_textx = x ;
lcd_texty = y ;
}
void
LCD_WipeLine ( unsigned char line )
void LCD_WipeLine ( unsigned char line )
{
unsigned char x ;
@ -294,8 +289,7 @@ LCD_WipeLine (unsigned char line)
lcd_frameupdate | = ( 1 < < line ) ;
}
void
Backlight_Off ( void )
void Backlight_Off ( void )
{
TWI_Start ( ) ;
TWI_Address_RW ( 0xc4 ) ;
@ -308,8 +302,7 @@ Backlight_Off (void)
TWI_Stop ( ) ;
}
void
Backlight_LED ( uint8_t led_selector )
void Backlight_LED ( uint8_t led_selector )
{
TWI_Start ( ) ;
TWI_Address_RW ( 0xc4 ) ;
@ -318,8 +311,7 @@ Backlight_LED (uint8_t led_selector)
TWI_Stop ( ) ;
}
void
Backlight_PWM ( uint8_t pwm , uint8_t prescaler , uint8_t value )
void Backlight_PWM ( uint8_t pwm , uint8_t prescaler , uint8_t value )
{
TWI_Start ( ) ;
TWI_Address_RW ( 0xc4 ) ;
@ -334,8 +326,7 @@ Backlight_PWM (uint8_t pwm, uint8_t prescaler, uint8_t value)
TWI_Stop ( ) ;
}
void
LCD_SavePage ( unsigned int page )
void LCD_SavePage ( unsigned int page )
{
// transfer framebuffer to dataflash using buffer 2
unsigned char line = 0 ;
@ -347,8 +338,7 @@ LCD_SavePage (unsigned int page)
}
}
void
LCD_LoadPage ( unsigned int page )
void LCD_LoadPage ( unsigned int page )
{
// transfer dataflash page to framebuffer
unsigned char line = 0 ;