daily_automated
This commit is contained in:
306
trunk/Arduino/libraries/sys64738/sys64738.cpp
Normal file
306
trunk/Arduino/libraries/sys64738/sys64738.cpp
Normal file
@@ -0,0 +1,306 @@
|
||||
/*
|
||||
sys64738.cpp - Library from sys64738.
|
||||
Created by Paolo Iocco, November 2, 2014.
|
||||
Released into the public domain.
|
||||
*/
|
||||
|
||||
//#include "Arduino.h"
|
||||
#include "sys64738.h"
|
||||
|
||||
|
||||
/*
|
||||
* Classe base per la grafica
|
||||
*/
|
||||
|
||||
graphic::graphic(void){
|
||||
_MaxX=84;
|
||||
_MaxY=48;
|
||||
_ch_width=6;
|
||||
_font=0;
|
||||
}
|
||||
void graphic::Clear(void){
|
||||
|
||||
}
|
||||
void graphic::Init(void){
|
||||
|
||||
}
|
||||
void graphic::Fillscreen(unsigned char FillData){
|
||||
|
||||
}
|
||||
void graphic::Locate (unsigned char x, unsigned char y){
|
||||
|
||||
}
|
||||
void graphic::WriteChar(char character, char font){
|
||||
|
||||
}
|
||||
|
||||
void graphic::WriteCharXY(unsigned char x, unsigned char y, char character, char font){
|
||||
Locate(x,y);
|
||||
WriteChar(character, font);
|
||||
}
|
||||
|
||||
void graphic::WriteString(char *characters, char font){
|
||||
while (*characters){
|
||||
WriteChar(*characters++,font);
|
||||
}
|
||||
}
|
||||
|
||||
void graphic::WriteStringXY(unsigned char x, unsigned char y, char *characters, char font){
|
||||
Locate(x,y);
|
||||
WriteString(characters,font);
|
||||
}
|
||||
|
||||
void graphic::Draw_BMP(unsigned char x0, unsigned char y0, unsigned char x1, unsigned char y1,const char BMP[]){
|
||||
|
||||
}
|
||||
|
||||
|
||||
//********************************************************************************************************************
|
||||
//** NOKIA 5110 Display over SPI
|
||||
|
||||
Display5110::Display5110(char PIN_SCE, char PIN_RESET, char PIN_DC, char PIN_SDIN, char PIN_SCLK){
|
||||
_PIN_SCE = PIN_SCE;
|
||||
_PIN_RESET = PIN_RESET;
|
||||
_PIN_DC = PIN_DC;
|
||||
_PIN_SDIN = PIN_SDIN;
|
||||
_PIN_SCLK = PIN_SCLK;
|
||||
_MaxX=84;
|
||||
_MaxY=48;
|
||||
}
|
||||
|
||||
void Display5110::Init(void){
|
||||
pinMode(_PIN_SCE, OUTPUT);
|
||||
pinMode(_PIN_RESET, OUTPUT);
|
||||
pinMode(_PIN_DC, OUTPUT);
|
||||
pinMode(_PIN_SDIN, OUTPUT);
|
||||
pinMode(_PIN_SCLK, OUTPUT);
|
||||
digitalWrite(_PIN_RESET, LOW);
|
||||
digitalWrite(_PIN_RESET, HIGH);
|
||||
WriteByte(LCD_C, 0x21 ); // set LCD mode:PDown=0, Vaddr=0, Hext=1
|
||||
WriteByte(LCD_C, 0xBC ); // set bias voltage, 0b(1)100.1000 (0x48) was: 0xB1
|
||||
WriteByte(LCD_C, 0x06 ); // temperature correction=0b(0000.01)10 was: 0x04
|
||||
WriteByte(LCD_C, 0x13 ); // set bias system: 0b(0001.0)011 --> 1:48 was: 0x14
|
||||
WriteByte(LCD_C, 0x20 ); // set LCD mode:PDown=0, Vaddr=0, Hext=0
|
||||
WriteByte(LCD_C, 0x0C ); // set LCD config, 0b(0000.1)100 --> normal mode
|
||||
digitalWrite(_PIN_SCE, LOW); // chip enable
|
||||
Clear();
|
||||
}
|
||||
|
||||
void Display5110::Clear(void){
|
||||
for (int index = 0; index < _MaxX * _MaxY / 8; index++){
|
||||
WriteByte(LCD_D, 0x00);
|
||||
}
|
||||
}
|
||||
|
||||
void Display5110::Locate(unsigned char x, unsigned char y){
|
||||
WriteByte( LCD_C, 0x80 | x); // Column.
|
||||
WriteByte( LCD_C, 0x40 | y); // Row.
|
||||
}
|
||||
|
||||
void Display5110::WriteChar(char character, char font){
|
||||
switch (font){
|
||||
case (FONT_4x6):
|
||||
_font=&font4x6[0][0];
|
||||
_ch_width=4;
|
||||
break;
|
||||
case (FONT_5x8):
|
||||
_font=&font5x8[0][0];
|
||||
_ch_width=5;
|
||||
break;
|
||||
case (FONT_6x8):
|
||||
_font=&font6x8[0][0];
|
||||
_ch_width=6;
|
||||
break;
|
||||
case (FONT_8x8):
|
||||
_font=&font8x8[0][0];
|
||||
_ch_width=8;
|
||||
break;
|
||||
case (FONT_C16):
|
||||
_font=&font_c16[0][0];
|
||||
_ch_width=8;
|
||||
break;
|
||||
}
|
||||
for (char index = 0; index < _ch_width; index++){
|
||||
WriteByte(LCD_D, pgm_read_byte(&(_font[_ch_width*character+index])));
|
||||
}
|
||||
}
|
||||
|
||||
void Display5110::WriteByte(byte dc, byte data){
|
||||
digitalWrite(_PIN_DC, dc);
|
||||
digitalWrite(_PIN_SCE, LOW);
|
||||
shiftOut(_PIN_SDIN, _PIN_SCLK, MSBFIRST, data);
|
||||
digitalWrite(_PIN_SCE, HIGH);
|
||||
}
|
||||
|
||||
void Display5110::SetContrast(unsigned char contrast) {
|
||||
WriteByte( 0x21, LCD_C ); // LCD Extended Commands.
|
||||
WriteByte( 0x80 | contrast, LCD_C ); // Set LCD Vop (Contrast).
|
||||
WriteByte( 0x20, LCD_C ); // LCD Standard Commands, horizontal addressing mode.
|
||||
}
|
||||
|
||||
//********************************************************************************************************************
|
||||
//** OLED 2 Colors display over I2C
|
||||
|
||||
DisplayIIC::DisplayIIC(int sda, int scl){
|
||||
_sda = sda;
|
||||
_scl = scl;
|
||||
pinMode(sda, OUTPUT);
|
||||
pinMode(scl, OUTPUT);
|
||||
}
|
||||
|
||||
// Comm start
|
||||
void DisplayIIC::Init(){
|
||||
IIC_Command(0xAE);//display off
|
||||
IIC_Command(0x00);//Set Memory Addressing Mode
|
||||
IIC_Command(0x10);//00,Horizontal Addressing Mode;01,Vertical Addressing Mode;10,Page Addressing Mode (RESET);11,Invalid
|
||||
IIC_Command(0x40);//Set Page Start Address for Page Addressing Mode,0-7
|
||||
IIC_Command(0x81);//Set COM Output Scan Direction
|
||||
IIC_Command(0xCF);//---set low column address
|
||||
IIC_Command(0xA1);//---set high column address
|
||||
IIC_Command(0xC8);//--set start line address
|
||||
IIC_Command(0xA6);//--set contrast control register
|
||||
IIC_Command(0xA8);
|
||||
IIC_Command(0x3F);//--set segment re-map 0 to 127
|
||||
IIC_Command(0xD3);//--set normal display
|
||||
IIC_Command(0x00);//--set multiplex ratio(1 to 64)
|
||||
IIC_Command(0xD5);//
|
||||
IIC_Command(0x80);//0xa4,Output follows RAM content;0xa5,Output ignores RAM content
|
||||
IIC_Command(0xD9);//-set display offset
|
||||
IIC_Command(0xF1);//-not offset
|
||||
IIC_Command(0xDA);//--set display clock divide ratio/oscillator frequency
|
||||
IIC_Command(0x12);//--set divide ratio
|
||||
IIC_Command(0xDB);//--set pre-charge period
|
||||
IIC_Command(0x40);//
|
||||
IIC_Command(0x20);//--set com pins hardware configuration
|
||||
IIC_Command(0x02);
|
||||
IIC_Command(0x8D);//--set vcomh
|
||||
IIC_Command(0x14);//0x20,0.77xVcc
|
||||
IIC_Command(0xA4);//--set DC-DC enable
|
||||
IIC_Command(0xA6);//
|
||||
IIC_Command(0xAF);//--turn on oled panel
|
||||
|
||||
|
||||
}
|
||||
void DisplayIIC::Clear(){
|
||||
FillScreen(0x00);
|
||||
}
|
||||
|
||||
void DisplayIIC::FillScreen(unsigned char fill_Data){
|
||||
unsigned char m,n;
|
||||
for(m=0;m<8;m++){
|
||||
IIC_Command(0xb0+m); //page0-page1
|
||||
IIC_Command(0x00); //low column start address
|
||||
IIC_Command(0x10); //high column start address
|
||||
IIC_Data();
|
||||
for(n=0;n<128;n++){
|
||||
IIC_WriteByte(fill_Data);
|
||||
}
|
||||
IIC_Stop();
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayIIC::Locate(unsigned char x, unsigned char y){
|
||||
IIC_Start();
|
||||
IIC_WriteByte(0x78); //Slave address,SA0=0
|
||||
IIC_WriteByte(0x00); //write command
|
||||
IIC_WriteByte(0xb0+y);
|
||||
IIC_WriteByte(((x&0xf0)>>4)|0x10);//|0x10
|
||||
IIC_WriteByte((x&0x0f)|0x00); //|0x01
|
||||
IIC_Stop();//SetPos
|
||||
}
|
||||
|
||||
void DisplayIIC::WriteChar(char character, char font){
|
||||
switch (font){
|
||||
case (FONT_4x6):
|
||||
_font=&font4x6[0][0];
|
||||
_ch_width=4;
|
||||
break;
|
||||
case (FONT_5x8):
|
||||
_font=&font5x8[0][0];
|
||||
_ch_width=5;
|
||||
break;
|
||||
case (FONT_6x8):
|
||||
_font=&font6x8[0][0];
|
||||
_ch_width=6;
|
||||
break;
|
||||
case (FONT_8x8):
|
||||
_font=&font8x8[0][0];
|
||||
_ch_width=8;
|
||||
break;
|
||||
case (FONT_C16):
|
||||
_font=&font_c16[0][0];
|
||||
_ch_width=8;
|
||||
break;
|
||||
}
|
||||
IIC_Data();
|
||||
for (char index = 0; index < _ch_width; index++){
|
||||
IIC_WriteByte(pgm_read_byte(&(_font[_ch_width*character+index])));
|
||||
}
|
||||
IIC_Stop();
|
||||
}
|
||||
|
||||
void DisplayIIC::Draw_BMP(unsigned char x0, unsigned char y0, unsigned char x1, unsigned char y1,const char BMP[]){
|
||||
unsigned int j=0;
|
||||
unsigned char x,y;
|
||||
|
||||
if(y1%8==0)
|
||||
y=y1/8;
|
||||
else
|
||||
y=y1/8+1;
|
||||
for(y=y0;y<y1;y++){
|
||||
Locate(x0,y);
|
||||
IIC_Data();
|
||||
for(x=x0;x<x1;x++){
|
||||
IIC_WriteByte(pgm_read_byte(&(BMP[j++])));
|
||||
}
|
||||
IIC_Stop();
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayIIC::IIC_Start(){
|
||||
digitalWrite(_scl, HIGH);
|
||||
digitalWrite(_sda, HIGH);
|
||||
digitalWrite(_sda, LOW);
|
||||
digitalWrite(_scl, LOW);
|
||||
}
|
||||
|
||||
//I2C Stop
|
||||
void DisplayIIC::IIC_Stop(){
|
||||
digitalWrite(_scl, LOW);
|
||||
digitalWrite(_sda, LOW);
|
||||
digitalWrite(_scl, HIGH);
|
||||
digitalWrite(_sda, HIGH);
|
||||
}
|
||||
|
||||
//Write Byte
|
||||
void DisplayIIC::IIC_WriteByte(unsigned char IIC_Byte){
|
||||
unsigned char i;
|
||||
for(i=0;i<8;i++){
|
||||
if((IIC_Byte << i) & 0x80)
|
||||
digitalWrite(_sda, HIGH);
|
||||
else
|
||||
digitalWrite(_sda, LOW);
|
||||
digitalWrite(_scl, HIGH);
|
||||
digitalWrite(_scl, LOW);
|
||||
// IIC_Byte<<=1;
|
||||
}
|
||||
digitalWrite(_sda, HIGH);
|
||||
digitalWrite(_scl, HIGH);
|
||||
digitalWrite(_scl, LOW);
|
||||
}
|
||||
|
||||
//Write Command
|
||||
void DisplayIIC::IIC_Command(unsigned char IIC_Command){
|
||||
IIC_Start();
|
||||
IIC_WriteByte(0x78); //Slave address,SA0=0
|
||||
IIC_WriteByte(0x00); //write command
|
||||
IIC_WriteByte(IIC_Command);
|
||||
IIC_Stop();
|
||||
}
|
||||
|
||||
//Write Begin_Data
|
||||
void DisplayIIC::IIC_Data(){
|
||||
IIC_Start();
|
||||
IIC_WriteByte(0x78);
|
||||
IIC_WriteByte(0x40); //write data
|
||||
}
|
||||
Reference in New Issue
Block a user