390 lines
14 KiB
C
390 lines
14 KiB
C
/*
|
|
* 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<<TXEN0);
|
|
// UCSRB= (1<<RXEN0)|(1<<TXEN0);
|
|
#endif // OLED_Serial
|
|
|
|
#ifdef OLED_SPI //init nel caso di trasmissione SPI
|
|
OLED_DDR |= BIT(SS_PIN);
|
|
OLED_DDR |= BIT(SCLK_PIN);
|
|
OLED_DDR |= BIT(SDIN_PIN);
|
|
SS_set;
|
|
SCLK_clr;
|
|
SDIN_clr;
|
|
_delay_ms(6);
|
|
#endif // OLED_SPI
|
|
};
|
|
|
|
/*--------------------------------------------------------------------------------------------------
|
|
Name : OLED_LineTo (x1, y1)
|
|
Description : traces a line from previous to the next point
|
|
Argument(s) : x1,y1: destination point
|
|
Return value : None.
|
|
--------------------------------------------------------------------------------------------------*/
|
|
void OLED_LineTo (unsigned char x1, unsigned char y1) {
|
|
OLED_putc('L');
|
|
OLED_putc('T');
|
|
OLED_putc(x1);
|
|
OLED_putc(y1);
|
|
}
|
|
|
|
/*--------------------------------------------------------------------------------------------------
|
|
Name : OLED_MoveArea (x, y, w, h, offsx, offsy)
|
|
Description : moves an entire area
|
|
Argument(s) : x,y: upper left corner; w: width; h: height; offsx, offsy: offset
|
|
Return value : None.
|
|
--------------------------------------------------------------------------------------------------*/
|
|
void OLED_MoveArea (unsigned char x, unsigned char y, unsigned char w, unsigned char h, unsigned char offsx, unsigned char offsy) {
|
|
OLED_putc('C');
|
|
OLED_putc('C');
|
|
OLED_putc(x);
|
|
OLED_putc(y);
|
|
OLED_putc(w);
|
|
OLED_putc(h);
|
|
OLED_putc(offsx);
|
|
OLED_putc(offsy);
|
|
}
|
|
|
|
/*--------------------------------------------------------------------------------------------------
|
|
Name : OLED_putc (dat)
|
|
Description : puts a byte on the communication port
|
|
Argument(s) : dat: byte to be transmitted
|
|
Return value : None.
|
|
--------------------------------------------------------------------------------------------------*/
|
|
void OLED_putc (unsigned char dat) {
|
|
#ifdef OLED_Serial
|
|
while (!(UCSRA & (1<<UDRE))) { /* warten bis Senden moeglich */
|
|
}
|
|
UDR = dat; /* sende Zeichen */
|
|
#endif
|
|
#ifdef OLED_SPI
|
|
unsigned char i;
|
|
SS_clr;
|
|
for(i=0;i<8;i++)
|
|
{
|
|
if(dat&0x80)
|
|
SDIN_set;
|
|
else
|
|
SDIN_clr;
|
|
SCLK_set;
|
|
dat = dat << 1;
|
|
SCLK_clr;
|
|
}
|
|
SS_set;
|
|
#endif
|
|
}
|
|
|
|
/*--------------------------------------------------------------------------------------------------
|
|
Name : OLED_SetFont (font)
|
|
Description : sets the current font
|
|
Argument(s) : font: availale fonts: 0 (default),6,10,18,51,120,123, user font: 200-203
|
|
Return value : None.
|
|
--------------------------------------------------------------------------------------------------*/
|
|
void OLED_SetFont (unsigned char font) {
|
|
OLED_putc('S');
|
|
OLED_putc('F');
|
|
OLED_putc(font);
|
|
}
|
|
|
|
/*--------------------------------------------------------------------------------------------------
|
|
Name : OLED_SetLinePattern (pattern)
|
|
Description : sets the line pattern
|
|
Argument(s) : pattern: bye pattern, eg. B=0xAA is dot line, B=0xFA is dash line
|
|
Return value : None.
|
|
--------------------------------------------------------------------------------------------------*/
|
|
void OLED_SetLinePattern (unsigned char pattern) {
|
|
OLED_putc('S');
|
|
OLED_putc('L');
|
|
OLED_putc('P');
|
|
OLED_putc(pattern);
|
|
}
|
|
|
|
/*--------------------------------------------------------------------------------------------------
|
|
Name : OLED_SetOutput(output)
|
|
Description : Sets the output pins
|
|
Argument(s) : output: bit field (bit0..4)
|
|
Return value : None.
|
|
--------------------------------------------------------------------------------------------------*/
|
|
void OLED_SetOutput (unsigned char output) {
|
|
OLED_putc('D');
|
|
OLED_putc('O');
|
|
OLED_putc('U');
|
|
OLED_putc('T');
|
|
OLED_putc(output);
|
|
}
|
|
|
|
/*--------------------------------------------------------------------------------------------------
|
|
Name : OLED_ShowConfig (mode)
|
|
Description : shows the communication config at startup
|
|
Argument(s) : mode: 0- off; 1- on
|
|
Return value : None.
|
|
--------------------------------------------------------------------------------------------------*/
|
|
void OLED_ShowConfig (unsigned char mode) {
|
|
OLED_putc('D');
|
|
OLED_putc('C');
|
|
OLED_putc(mode); // 0 off, 1 on
|
|
}
|
|
|
|
/*--------------------------------------------------------------------------------------------------
|
|
Name : OLED_ShowCursor (mode)
|
|
Description : shows the text cursor
|
|
Argument(s) : mode: 0-off; 1- on
|
|
Return value : None.
|
|
--------------------------------------------------------------------------------------------------*/
|
|
void OLED_ShowCursor (unsigned char mode) {
|
|
OLED_putc('C');
|
|
OLED_putc('S');
|
|
OLED_putc(mode); // 0 off, 1 on
|
|
}
|
|
|
|
/*--------------------------------------------------------------------------------------------------
|
|
Name : OLED_ShowSplashScreen (mode)
|
|
Description : Displays a splash screen at startup
|
|
Argument(s) : mode:0 = off, 1 = on
|
|
Return value : None.
|
|
--------------------------------------------------------------------------------------------------*/
|
|
void OLED_ShowSplashScreen (unsigned char mode){
|
|
OLED_putc('D');
|
|
OLED_putc('S');
|
|
OLED_putc('S');
|
|
OLED_putc(mode);
|
|
}
|
|
|
|
/*--------------------------------------------------------------------------------------------------
|
|
Name : OLED_SplashScreen (length, *data)
|
|
Description : defines the splash screen
|
|
Argument(s) : length: dimension; data: pointer to bitmap
|
|
Return value : None.
|
|
--------------------------------------------------------------------------------------------------*/
|
|
void OLED_SplashScreen (int length, const unsigned char *data) {
|
|
int j;
|
|
|
|
OLED_putc('S');
|
|
OLED_putc('S');
|
|
OLED_putc('S');
|
|
OLED_putc((unsigned char) (length % 256));
|
|
OLED_putc((unsigned char) (length / 256));
|
|
for (j = 0; j < length;j++) {
|
|
if((j%32)==0)
|
|
_delay_ms(50);
|
|
_delay_ms(5);
|
|
OLED_putc(*(data+j));
|
|
}
|
|
}
|
|
|
|
/*--------------------------------------------------------------------------------------------------
|
|
Name : OLED_UserFont (sect, length, *data)
|
|
Description : uploads an user font (sections 200-205)
|
|
Argument(s) : sect: section 200-205; length: dimension; data: pointer to font bitmaps
|
|
Return value : None.
|
|
--------------------------------------------------------------------------------------------------*/
|
|
void OLED_UserFont (unsigned char sect, int length, const unsigned char *data) {
|
|
int j;
|
|
|
|
OLED_putc('S');
|
|
OLED_putc('U');
|
|
OLED_putc('F');
|
|
OLED_putc(sect);
|
|
OLED_putc((unsigned char) (length % 256));
|
|
OLED_putc((unsigned char) (length / 256));
|
|
for (j = 0; j < length;j++) {
|
|
if((j%32)==0)
|
|
_delay_ms(50);
|
|
_delay_ms(5);
|
|
OLED_putc(*(data+j));
|
|
}
|
|
}
|
|
|
|
/*--------------------------------------------------------------------------------------------------
|
|
Name : OLED_Write (*string)
|
|
Description : Displays a string at current cursor location. Terminates with EOL
|
|
Argument(s) : s: string
|
|
Return value : None.
|
|
--------------------------------------------------------------------------------------------------*/
|
|
void OLED_Write (char *string){
|
|
OLED_putc('T');
|
|
OLED_putc('T');
|
|
while (*string) {
|
|
OLED_putc(*string);
|
|
string++;
|
|
}
|
|
OLED_putc(0x00); //EOL
|
|
}
|
|
|
|
/*--------------------------------------------------------------------------------------------------
|
|
Name : OLED_WriteXY (x, y, *string)
|
|
Description : Displays a string at x,y. Terminates with EOL
|
|
Argument(s) : x,y: position. s: string
|
|
Return value : None.
|
|
--------------------------------------------------------------------------------------------------*/
|
|
void OLED_WriteXY (unsigned char x, unsigned char y, char *string) {
|
|
OLED_GotoXY(x,y,1);
|
|
OLED_Write(string);
|
|
}
|
|
|