/* * digole.c * * Created on: 27.01.2014 * Author: q242695 */ #include "digole.h" /*-------------------------------------------------------------------------------------------------- Definitions --------------------------------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------------------------------- Function definitions --------------------------------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------------------------------- Name : OLED_Cls () Description : Clears the screen Argument(s) : None. Return value : None. --------------------------------------------------------------------------------------------------*/ void OLED_Cls (void) { OLED_putc('C'); OLED_putc('L'); } /*-------------------------------------------------------------------------------------------------- Name : OLED_CR () Description : Sends a Carriage Return Argument(s) : None. Return value : None. --------------------------------------------------------------------------------------------------*/ void OLED_CR (void) { OLED_putc(0x00); OLED_putc('T'); OLED_putc('R'); OLED_putc('T'); } /*-------------------------------------------------------------------------------------------------- Name : OLED_DisplayMode (mode) Description : Sets the display output mode Argument(s) : mode (0 = NOT; 1 = OR; 2 = XOR; 3 = AND. Default = OR) Return value : None. --------------------------------------------------------------------------------------------------*/ void OLED_DisplayMode (unsigned char mode) { OLED_putc('D'); OLED_putc('M'); switch (mode) { case 0: mode='!'; break; // not case 1: mode='|'; break; // or case 2: mode='^'; break; // xor case 3: mode='&'; break; // and default: mode='|'; // default is or } OLED_putc(mode); } /*-------------------------------------------------------------------------------------------------- Name : OLED_DrawBmp (x, y, w, h, *bitmap) Description : Displays a bitmap at x,y Argument(s) : x,y: coordinates. w,h: dimensions. Bitmap: pointer to data Return value : None. --------------------------------------------------------------------------------------------------*/ void OLED_DrawBmp (unsigned char x, unsigned char y, unsigned char w, unsigned char h, const unsigned char *bitmap) { unsigned char i = 0; if ((w & 7) != 0) i = 1; OLED_putc('D'); OLED_putc('I'); OLED_putc('M'); OLED_putc(x); OLED_putc(y); OLED_putc(w); OLED_putc(h); for (int j = 0; j < h * ((w >> 3) + i); j++) { OLED_putc(*(bitmap + j)); _delay_ms(5); } } /*-------------------------------------------------------------------------------------------------- Name : OLED_DrawCircle (x, y, radius, mode) Description : Draws a circle Argument(s) : x,y: center coordinates. Radius: radius. Mode: 0 = empty, 1 = filled, Return value : None. --------------------------------------------------------------------------------------------------*/ void OLED_DrawCircle (unsigned char x, unsigned char y, unsigned char radius, unsigned char mode) { OLED_putc('C'); OLED_putc('C'); OLED_putc(x); OLED_putc(y); OLED_putc(radius); OLED_putc(mode); // 1 = filled, 0 = empty } /*-------------------------------------------------------------------------------------------------- Name : OLED_DrawLine (x1,y1,x2,y2) Description : Draws a line from x1,y1 to x2,y2 Argument(s) : x1,y1: first point. x2,y2: second point. Return value : None. --------------------------------------------------------------------------------------------------*/ void OLED_DrawLine (unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2) { OLED_putc('L'); OLED_putc('N'); OLED_putc(x1); OLED_putc(y1); OLED_putc(x2); OLED_putc(y2); } /*-------------------------------------------------------------------------------------------------- Name : OLED_DrawRect (x1, y1, x2, y2, mode) Description : Displays a rectangle Argument(s) : x1,y1: first point. x2,y2: second point. Mode: 0 = empty 1 = filled Return value : None. --------------------------------------------------------------------------------------------------*/ void OLED_DrawRect (unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2, unsigned char mode) { if (mode){ OLED_putc('F'); // filled rectangle, <>0 } else { OLED_putc('D'); // outlined rectangle, ==0 } OLED_putc('R'); OLED_putc(x1); OLED_putc(y1); OLED_putc(x2); OLED_putc(y2); } /*-------------------------------------------------------------------------------------------------- Name : OLED_GotoXY (x, y, mode) Description : go to x,y position on the screen. Argument(s) : x,y: position; mode=1: text; mode=0: graphic Return value : None. --------------------------------------------------------------------------------------------------*/ void OLED_GotoXY (unsigned char x, unsigned char y, unsigned char mode) { if (mode==1){ OLED_putc('T'); } else { OLED_putc('G'); } OLED_putc('P'); OLED_putc(x); OLED_putc(y); } /*-------------------------------------------------------------------------------------------------- Name : OLED_Init () Description : Initializes the display Argument(s) : None. Return value : None. --------------------------------------------------------------------------------------------------*/ void OLED_Init (void) { #ifdef OLED_Serial UBRRH = UBRRH_VALUE; UBRRL = UBRRL_VALUE; #if USE_2X0 UCSRA |= (1 << U2X); #else UCSRA &= ~(1 << U2X); #endif UCSRC= _BV(UCSZ01) | _BV(UCSZ00); // 8 N 1 UCSRB= (1<