|  |  | @ -15,62 +15,56 @@ uint8_t lcd_frameupdate = 0; | 
			
		
	
		
		
			
				
					
					|  |  |  | uint8_t lcd_textx = 0; |  |  |  | uint8_t lcd_textx = 0; | 
			
		
	
		
		
			
				
					
					|  |  |  | uint8_t lcd_texty = 0; |  |  |  | uint8_t lcd_texty = 0; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | // Prevent Double Initialization
 |  |  |  | void | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | unsigned short LCD_flag = 0; |  |  |  | LCD_Send (uint8_t data) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | void LCD_Send(uint8_t data) |  |  |  |  | 
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | { |  |  |  | { | 
			
		
	
		
		
			
				
					
					|  |  |  |   SPI_MasterTransfer(data); |  |  |  |   SPI_MasterTransfer(data); | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | void LCD_Init(void) |  |  |  | void | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | LCD_Init (void) | 
			
		
	
		
		
			
				
					
					|  |  |  | { |  |  |  | { | 
			
		
	
		
		
			
				
					
					|  |  |  |   // Check if already initialized
 |  |  |  |   SPI_MasterInit(); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |   if (!(LCD_flag & 1)) |  |  |  | 
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |   { |  |  |  |   /* Set Register Select and Chip Select as Output */ | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     SPI_MasterInit(); |  |  |  |   DDRC |= (1<<PC7)|(1<<PC6); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |    | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     // Set Register Select and Chip Select as Output
 |  |  |  |   /* Backup Status Register and disable Interrupts */ | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     DDRC |= (1 << PC7) | (1 << PC6); |  |  |  |   uint8_t sreg = SREG; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |   cli(); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     // Backup Status Register and disable Interrupts
 |  |  |  |    | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     uint8_t sreg = SREG; |  |  |  |   /* Starting Init Command Sequence */ | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     cli(); |  |  |  |   LCD_Command_Mode; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |   LCD_Chip_Select; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     // Starting Init Command Sequence
 |  |  |  | 
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     LCD_Command_Mode; |  |  |  |   LCD_Send(LCD_RESET); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     LCD_Chip_Select; |  |  |  |   LCD_Send(LCD_BIAS_1_7); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |   LCD_Send(LCD_ELECTRONIC_VOLUME_MODE_SET); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     LCD_Send(LCD_RESET); |  |  |  |   LCD_Send(0x08); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     LCD_Send(LCD_BIAS_1_7); |  |  |  |   LCD_Send(LCD_ADC_SELECT_NORMAL); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     LCD_Send(LCD_ELECTRONIC_VOLUME_MODE_SET); |  |  |  |   LCD_Send(LCD_COMMON_OUTPUT_MODE_REVERSE); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     LCD_Send(0x08); |  |  |  |   LCD_Send(LCD_V5_VOLTAGE_REGULATOR | 0x05); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     LCD_Send(LCD_ADC_SELECT_NORMAL); |  |  |  |   LCD_Send(LCD_POWER_CONTROLLER_SET | 0x07); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     LCD_Send(LCD_COMMON_OUTPUT_MODE_REVERSE); |  |  |  |   LCD_Send(LCD_DISPLAY_ON); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     LCD_Send(LCD_V5_VOLTAGE_REGULATOR | 0x05); |  |  |  |    | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     LCD_Send(LCD_POWER_CONTROLLER_SET | 0x07); |  |  |  |   LCD_Chip_Unselect; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     LCD_Send(LCD_DISPLAY_ON); |  |  |  |   LCD_Data_Mode; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |    | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     LCD_Chip_Unselect; |  |  |  |   LCD_Clear(); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     LCD_Data_Mode; |  |  |  |    | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |   /* Restore Status Register */ | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     LCD_Clear(); |  |  |  |   SREG = sreg; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |    | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     // Restore Status Register
 |  |  |  |   // Initialize TWI for Backlight Control
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     SREG = sreg; |  |  |  |   TWI_Init(); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |   Backlight_Off(); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     // Initialize TWI for Backlight Control
 |  |  |  |    | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     TWI_Init(); |  |  |  |   // Initialize Dataflash
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     Backlight_Off(); |  |  |  |   dataflash_init(); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     // 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; |  |  |  |   uint8_t x = 0, y = 0; | 
			
		
	
		
		
			
				
					
					|  |  |  |    |  |  |  |    | 
			
		
	
	
		
		
			
				
					|  |  | @ -83,72 +77,76 @@ void LCD_Clear(void) | 
			
		
	
		
		
			
				
					
					|  |  |  |   LCD_Update(); |  |  |  |   LCD_Update(); | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | void LCD_Update(void) |  |  |  | void | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | LCD_Update (void) | 
			
		
	
		
		
			
				
					
					|  |  |  | { |  |  |  | { | 
			
		
	
		
		
			
				
					
					|  |  |  |   int8_t page = 7; |  |  |  |   int8_t page = 7; | 
			
		
	
		
		
			
				
					
					|  |  |  |    |  |  |  |    | 
			
		
	
		
		
			
				
					
					|  |  |  |   // Backup Status Register and disable Interrupts
 |  |  |  |   /* Backup Status Register and disable Interrupts */ | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |   uint8_t sreg = SREG; |  |  |  |   uint8_t sreg = SREG; | 
			
		
	
		
		
			
				
					
					|  |  |  |   cli(); |  |  |  |   cli(); | 
			
		
	
		
		
			
				
					
					|  |  |  |    |  |  |  |    | 
			
		
	
		
		
			
				
					
					|  |  |  |   do |  |  |  |   do | 
			
		
	
		
		
			
				
					
					|  |  |  |   { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     if (lcd_frameupdate & (1 << page)) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     { |  |  |  |     { | 
			
		
	
		
		
			
				
					
					|  |  |  |       LCD_Chip_Select; |  |  |  |       if (lcd_frameupdate & (1<<page)) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       LCD_Command_Mode; |  |  |  |         { | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |           LCD_Chip_Select; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |           LCD_Command_Mode; | 
			
		
	
		
		
			
				
					
					|  |  |  |            |  |  |  |            | 
			
		
	
		
		
			
				
					
					|  |  |  |       LCD_Send(LCD_PAGE_ADDRESS_SET | page); |  |  |  |           LCD_Send(LCD_PAGE_ADDRESS_SET | page); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       LCD_Send(LCD_COLUMN_ADDRESS_SET_H); |  |  |  |           LCD_Send(LCD_COLUMN_ADDRESS_SET_H); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       LCD_Send(LCD_COLUMN_ADDRESS_SET_L); |  |  |  |           LCD_Send(LCD_COLUMN_ADDRESS_SET_L); | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |            |  |  |  |            | 
			
		
	
		
		
			
				
					
					|  |  |  |       LCD_Data_Mode; |  |  |  |           LCD_Data_Mode; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |            |  |  |  |            | 
			
		
	
		
		
			
				
					
					|  |  |  |       for (uint8_t x = 0; x < 128; x++) |  |  |  |           for (uint8_t x = 0; x < 128; x++) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         LCD_Send(lcd_framebuffer[page][x]); |  |  |  |             LCD_Send(lcd_framebuffer[page][x]); | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |            |  |  |  |            | 
			
		
	
		
		
			
				
					
					|  |  |  |       LCD_Chip_Unselect; |  |  |  |           LCD_Chip_Unselect; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |   } while (page--); |  |  |  |   while (page--); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |    |  |  |  |    | 
			
		
	
		
		
			
				
					
					|  |  |  |   lcd_frameupdate = 0; |  |  |  |   lcd_frameupdate = 0; | 
			
		
	
		
		
			
				
					
					|  |  |  |    |  |  |  |    | 
			
		
	
		
		
			
				
					
					|  |  |  |   // Restore Status Register
 |  |  |  |   /* Restore Status Register */ | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |   SREG = sreg; |  |  |  |   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
 |  |  |  |   // Check if x and y are within display coordinates
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   if ((x < 128) && (y < 64)) |  |  |  |   if ((x < 128) && (y < 64)) | 
			
		
	
		
		
			
				
					
					|  |  |  |   { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     // Precalculate Page and Pixel values
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     uint8_t page = (y / 8); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     uint8_t pixel = (1 << (y % 8)); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     switch (mode) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     { |  |  |  |     { | 
			
		
	
		
		
			
				
					
					|  |  |  |     case 0: |  |  |  |       // Precalculate Page and Pixel values
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       // Clear Pixel
 |  |  |  |       uint8_t page = (y / 8); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       lcd_framebuffer[page][x] &= ~pixel; |  |  |  |       uint8_t pixel = (1 << (y % 8)); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       break; |  |  |  |        | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |       switch (mode) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     case 2: |  |  |  |         { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       // Toggle Pixel
 |  |  |  |         case 0: | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       lcd_framebuffer[page][x] ^= pixel; |  |  |  |           // Clear Pixel
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       break; |  |  |  |           lcd_framebuffer[page][x] &= ~pixel; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |           break; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     default: |  |  |  |          | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       // Set Pixel
 |  |  |  |         case 2: | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       lcd_framebuffer[page][x] |= pixel; |  |  |  |           // Toggle Pixel
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       break; |  |  |  |           lcd_framebuffer[page][x] ^= pixel; | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |           break; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |          | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         default: | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |           // Set Pixel
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |           lcd_framebuffer[page][x] |= pixel; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |           break; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |          | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       lcd_frameupdate |= (1 << page); | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     lcd_frameupdate |= (1 << page); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |   } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 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
 |  |  |  |   // look here: http://de.wikipedia.org/wiki/Bresenham-Algorithmus
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   int8_t dx = abs(x1 - x0); |  |  |  |   int8_t dx = abs(x1 - x0); | 
			
		
	
	
		
		
			
				
					|  |  | @ -159,29 +157,30 @@ void LCD_DrawLine(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t mode) | 
			
		
	
		
		
			
				
					
					|  |  |  |   int8_t e2; |  |  |  |   int8_t e2; | 
			
		
	
		
		
			
				
					
					|  |  |  |    |  |  |  |    | 
			
		
	
		
		
			
				
					
					|  |  |  |   for (;;) |  |  |  |   for (;;) | 
			
		
	
		
		
			
				
					
					|  |  |  |   { |  |  |  |     { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     LCD_DrawPixel(x0, y0, mode); |  |  |  |       LCD_DrawPixel(x0, y0, mode); | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |        |  |  |  |        | 
			
		
	
		
		
			
				
					
					|  |  |  |     if (x0 == x1 && y0 == y1) |  |  |  |       if (x0 == x1 && y0 == y1) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       break; |  |  |  |         break; | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |        |  |  |  |        | 
			
		
	
		
		
			
				
					
					|  |  |  |     e2 = err; |  |  |  |       e2 = err; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |        |  |  |  |        | 
			
		
	
		
		
			
				
					
					|  |  |  |     if (e2 > -dx) |  |  |  |       if (e2 > -dx) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     { |  |  |  |         { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       err -= dy; |  |  |  |           err -= dy; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       x0 += sx; |  |  |  |           x0 += sx; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |         } | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |        |  |  |  |        | 
			
		
	
		
		
			
				
					
					|  |  |  |     if (e2 < dy) |  |  |  |       if (e2 < dy) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     { |  |  |  |         { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       err += dx; |  |  |  |           err += dx; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       y0 += sy; |  |  |  |           y0 += sy; | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |   } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 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
 |  |  |  |   // look here: http://de.wikipedia.org/wiki/Bresenham-Algorithmus
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   int8_t f = 1 - radius; |  |  |  |   int8_t f = 1 - radius; | 
			
		
	
	
		
		
			
				
					|  |  | @ -196,90 +195,96 @@ void LCD_DrawCircle(uint8_t x0, uint8_t y0, uint8_t radius, uint8_t mode) | 
			
		
	
		
		
			
				
					
					|  |  |  |   LCD_DrawPixel(x0 - radius, y0, mode); |  |  |  |   LCD_DrawPixel(x0 - radius, y0, mode); | 
			
		
	
		
		
			
				
					
					|  |  |  |    |  |  |  |    | 
			
		
	
		
		
			
				
					
					|  |  |  |   while (x < y) |  |  |  |   while (x < y) | 
			
		
	
		
		
			
				
					
					|  |  |  |   { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     if (f >= 0) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     { |  |  |  |     { | 
			
		
	
		
		
			
				
					
					|  |  |  |       y--; |  |  |  |       if (f >= 0) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       ddF_y += 2; |  |  |  |         { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       f += ddF_y; |  |  |  |           y--; | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |           ddF_y += 2; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |           f += ddF_y; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |        | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       x++; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       ddF_x += 2; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       f += ddF_x + 1; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |        | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       LCD_DrawPixel(x0 + x, y0 + y, mode); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       LCD_DrawPixel(x0 - x, y0 + y, mode); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       LCD_DrawPixel(x0 + x, y0 - y, mode); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       LCD_DrawPixel(x0 - x, y0 - y, mode); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       LCD_DrawPixel(x0 + y, y0 + x, mode); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       LCD_DrawPixel(x0 - y, y0 + x, mode); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       LCD_DrawPixel(x0 + y, y0 - x, mode); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       LCD_DrawPixel(x0 - y, y0 - x, mode); | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     x++; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     ddF_x += 2; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     f += ddF_x + 1; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     LCD_DrawPixel(x0 + x, y0 + y, mode); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     LCD_DrawPixel(x0 - x, y0 + y, mode); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     LCD_DrawPixel(x0 + x, y0 - y, mode); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     LCD_DrawPixel(x0 - x, y0 - y, mode); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     LCD_DrawPixel(x0 + y, y0 + x, mode); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     LCD_DrawPixel(x0 - y, y0 + x, mode); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     LCD_DrawPixel(x0 + y, y0 - x, mode); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     LCD_DrawPixel(x0 - y, y0 - x, mode); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |   } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | void LCD_PutChar(const char c) |  |  |  | void | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | LCD_PutChar (const char c) | 
			
		
	
		
		
			
				
					
					|  |  |  | { |  |  |  | { | 
			
		
	
		
		
			
				
					
					|  |  |  |   // basic support for cr und new line
 |  |  |  |   // basic support for cr und new line
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   switch (c) |  |  |  |   switch (c) | 
			
		
	
		
		
			
				
					
					|  |  |  |   { |  |  |  |     { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |   case '\r': |  |  |  |     case '\r': | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     // Carriage Return
 |  |  |  |       // Carriage Return
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     lcd_textx = 0; |  |  |  |       lcd_textx = 0; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     break; |  |  |  |       break; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |        | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |   case '\n': |  |  |  |     case '\n': | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     // New Line
 |  |  |  |       // New Line
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     if (lcd_texty < 7) |  |  |  |       if (lcd_texty < 7) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       lcd_texty++; |  |  |  |         lcd_texty++; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     break; |  |  |  |       break; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |        | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |   default: |  |  |  |     default: | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     for (uint8_t x = 0; x < 6; x++) |  |  |  |       for (uint8_t x = 0; x < 6; x++) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       lcd_framebuffer[lcd_texty][(lcd_textx * 6) + x] = pgm_read_byte(&font[(uint8_t)(c)][x]); |  |  |  |         lcd_framebuffer[lcd_texty][(lcd_textx * 6) + x] = pgm_read_byte(&font[(uint8_t)(c)][x]); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |        | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     lcd_frameupdate |= (1 << lcd_texty); |  |  |  |       lcd_frameupdate |= (1 << lcd_texty); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |    | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     if (lcd_textx < 20) |  |  |  |       if (lcd_textx < 20) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       lcd_textx++; |  |  |  |         lcd_textx++; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     break; |  |  |  |       break; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |   } |  |  |  |     } | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | void LCD_PutString(const char *s) |  |  |  | void | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | LCD_PutString (const char *s) | 
			
		
	
		
		
			
				
					
					|  |  |  | { |  |  |  | { | 
			
		
	
		
		
			
				
					
					|  |  |  |   // no empty strings allowed!
 |  |  |  |   // no empty strings allowed!
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   if (*s) |  |  |  |   if (*s) | 
			
		
	
		
		
			
				
					
					|  |  |  |   { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     do |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     { |  |  |  |     { | 
			
		
	
		
		
			
				
					
					|  |  |  |       LCD_PutChar(*s); |  |  |  |       do | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     } while (*(++s)); |  |  |  |         { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |   } |  |  |  |           LCD_PutChar(*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++; |  |  |  |       s++; | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     if (c == '\0') |  |  |  |       if (c == '\0') | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       break; |  |  |  |         break; | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |        |  |  |  |        | 
			
		
	
		
		
			
				
					
					|  |  |  |     LCD_PutChar(c); |  |  |  |       LCD_PutChar(c); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |   } |  |  |  |     } | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | void LCD_GotoXY(uint8_t x, uint8_t y) |  |  |  | void | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | LCD_GotoXY (uint8_t x, uint8_t y) | 
			
		
	
		
		
			
				
					
					|  |  |  | { |  |  |  | { | 
			
		
	
		
		
			
				
					
					|  |  |  |   lcd_textx = x; |  |  |  |   lcd_textx = x; | 
			
		
	
		
		
			
				
					
					|  |  |  |   lcd_texty = y; |  |  |  |   lcd_texty = y; | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | void LCD_WipeLine(unsigned char line) |  |  |  | void | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | LCD_WipeLine (unsigned char line) | 
			
		
	
		
		
			
				
					
					|  |  |  | { |  |  |  | { | 
			
		
	
		
		
			
				
					
					|  |  |  |   unsigned char x; |  |  |  |   unsigned char x; | 
			
		
	
		
		
			
				
					
					|  |  |  |    |  |  |  |    | 
			
		
	
	
		
		
			
				
					|  |  | @ -289,7 +294,8 @@ void LCD_WipeLine(unsigned char line) | 
			
		
	
		
		
			
				
					
					|  |  |  |   lcd_frameupdate |= (1 << line); |  |  |  |   lcd_frameupdate |= (1 << line); | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | void Backlight_Off(void) |  |  |  | void | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | Backlight_Off (void) | 
			
		
	
		
		
			
				
					
					|  |  |  | { |  |  |  | { | 
			
		
	
		
		
			
				
					
					|  |  |  |   TWI_Start(); |  |  |  |   TWI_Start(); | 
			
		
	
		
		
			
				
					
					|  |  |  |   TWI_Address_RW(0xc4); |  |  |  |   TWI_Address_RW(0xc4); | 
			
		
	
	
		
		
			
				
					|  |  | @ -302,7 +308,8 @@ void Backlight_Off(void) | 
			
		
	
		
		
			
				
					
					|  |  |  |   TWI_Stop(); |  |  |  |   TWI_Stop(); | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | void Backlight_LED(uint8_t led_selector) |  |  |  | void | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | Backlight_LED (uint8_t led_selector) | 
			
		
	
		
		
			
				
					
					|  |  |  | { |  |  |  | { | 
			
		
	
		
		
			
				
					
					|  |  |  |   TWI_Start(); |  |  |  |   TWI_Start(); | 
			
		
	
		
		
			
				
					
					|  |  |  |   TWI_Address_RW(0xc4); |  |  |  |   TWI_Address_RW(0xc4); | 
			
		
	
	
		
		
			
				
					|  |  | @ -311,7 +318,8 @@ void Backlight_LED(uint8_t led_selector) | 
			
		
	
		
		
			
				
					
					|  |  |  |   TWI_Stop(); |  |  |  |   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_Start(); | 
			
		
	
		
		
			
				
					
					|  |  |  |   TWI_Address_RW(0xc4); |  |  |  |   TWI_Address_RW(0xc4); | 
			
		
	
	
		
		
			
				
					|  |  | @ -326,27 +334,29 @@ void Backlight_PWM(uint8_t pwm, uint8_t prescaler, uint8_t value) | 
			
		
	
		
		
			
				
					
					|  |  |  |   TWI_Stop(); |  |  |  |   TWI_Stop(); | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | void LCD_SavePage(unsigned int page) |  |  |  | void | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | LCD_SavePage (unsigned int page) | 
			
		
	
		
		
			
				
					
					|  |  |  | { |  |  |  | { | 
			
		
	
		
		
			
				
					
					|  |  |  |   // transfer framebuffer to dataflash using buffer 2
 |  |  |  |   // transfer framebuffer to dataflash using buffer 2
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   unsigned char line = 0; |  |  |  |   unsigned char line = 0; | 
			
		
	
		
		
			
				
					
					|  |  |  |    |  |  |  |    | 
			
		
	
		
		
			
				
					
					|  |  |  |   for (line = 0; line < 8; line++) |  |  |  |   for (line = 0; line < 8; line++) | 
			
		
	
		
		
			
				
					
					|  |  |  |   { |  |  |  |     { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     dataflash_buffer_write(2, 0, 128, lcd_framebuffer[line]); |  |  |  |       dataflash_buffer_write(2, 0, 128, lcd_framebuffer[line]); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     dataflash_buffer_to_page(page + line, 2); |  |  |  |       dataflash_buffer_to_page(page + line, 2); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |   } |  |  |  |     } | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | void LCD_LoadPage(unsigned int page) |  |  |  | void | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | LCD_LoadPage (unsigned int page) | 
			
		
	
		
		
			
				
					
					|  |  |  | { |  |  |  | { | 
			
		
	
		
		
			
				
					
					|  |  |  |   // transfer dataflash page to framebuffer
 |  |  |  |   // transfer dataflash page to framebuffer
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   unsigned char line = 0; |  |  |  |   unsigned char line = 0; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   for (line = 0; line < 8; line++) |  |  |  |   for (line = 0; line < 8; line++) | 
			
		
	
		
		
			
				
					
					|  |  |  |   { |  |  |  |     { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     dataflash_read(page + line, 0, 128, lcd_framebuffer[line]); |  |  |  |       dataflash_read(page + line, 0, 128, lcd_framebuffer[line]); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |   } |  |  |  |     } | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   // mark all lines to be updated
 |  |  |  |   // mark all lines to be updated
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   lcd_frameupdate = 0xff; |  |  |  |   lcd_frameupdate = 0xff; | 
			
		
	
	
		
		
			
				
					|  |  | 
 |