C:\Users\jdn\Desktop\GithubJDN\Oled\OledMap_ino.
asm
Program "OledMap.h" Assembly of the 7 Oled libs for 1k bitmap. 170611 }
MIT License // set pointer
//=============== byte saveLi,saveCol;
Routine "OledGenc.h" void SetLine (byte cc) {
#include <avr/pgmspace.h> saveLi=cc;
const uint8_t didel[] PROGMEM = {0x82,0xf2,0xfe,0xfe,0x8e,0x82,0xc2,0x3c,0x00 ptMap = 128*saveLi+saveCol;
0xc0,0xf8,0xfd,0x3d,0x0d,0x00, \ }
0x82,0xf2,0xfe,0xfe,0x8e,0x82,0xc2,0x3c,0x00, \ void SetCol (byte cc) {
0xc0,0xf8,0xfe,0xfe,0x96,0x92,0x82,0x02,0x00, \ saveCol=cc;
0xc0,0xf8,0xfe,0xfe,0x86,0x80,0x80,0x80,0x80 }; ptMap = 128*saveLi+saveCol;
const uint8_t taNum[] PROGMEM = { }
0x00,0x00,0x00,0x00, 0x00,0xc0,0xde,0x00, // space ! void LiCol (byte li,byte cc) {
0x03,0x00,0x03,0x00, 0x74,0x2f,0x74,0x2f, // " # saveLi=li; saveCol=cc;
0x2c,0x49,0xff,0x39, 0x43,0x33,0x6c,0x63, // $ % ptMap = (128*saveLi)+saveCol;
0x6e,0x59,0x19,0x26, 0x00,0x05,0x03,0x00, // & ' }
0x1c,0x22,0x41,0x00, 0x00,0x41,0x22,0x1c, // ( ) void GetLiCol () {
0x2a,0x1c,0x1c,0x2a, 0x08,0x3e,0x08,0x08, // * + saveLi=ptMap/128; saveCol=ptMap%128;
0x00,0xa0,0x60,0x00, 0x08,0x08,0x08,0x08, // , - }
0x00,0xc0,0xc0,0x00, 0x03,0x0c,0x30,0xc0, // . /
0x3e,0x41,0x41,0x3e, 0x04,0x02,0x7f,0x00, // 0 1 #define Sprite(tt) \
0x62,0x51,0x49,0x46, 0x22,0x41,0x49,0x36, // 2 3 for (byte i=0; i<sizeof tt; i++) \
0x1c,0x12,0x79,0x10, 0x2f,0x49,0x49,0x31, // 4 5 { taMap[ptMap++] = pgm_read_byte(&tt[i]); }
0x36,0x49,0x49,0x31, 0x41,0x31,0x0d,0x03, // 6 7
0x36,0x49,0x49,0x36, 0x46,0x49,0x49,0x3e, // 8 9 // For the character generators
0x00,0x36,0x36,0x00, 0x00,0xd6,0x76,0x00, // : ; #define Copy(tt) \
0x08,0x14,0x22,0x41, 0x24,0x24,0x24,0x24, // < = for (byte i=0; i<sizeof tt/4; i++) { \
0x41,0x22,0x14,0x08, 0x02,0xc1,0xd9,0x06}; // > ? for (byte j=0; j<4; j++) {taMap[ptMap++] = (pgm_read_byte(&tt[4*i+j]));} \
const uint8_t taMaj[] PROGMEM = { taMap[i++]=0;
0x39,0x48,0x71,0x41,0x3e, 0x7e,0x11,0x11,0x11,0x7e, // @ A // Maj en 5 de large
0x7f,0x49,0x49,0x49,0x36, 0x3e,0x41,0x41,0x41,0x22, // B C #define CopyMaj(tt) \
0x7f,0x41,0x41,0x41,0x3e, 0x7f,0x49,0x49,0x41,0x41, // D,E for (byte i=0; i<sizeof tt/5; i++) { \
0x7f,0x09,0x09,0x01,0x01, // F for (byte j=0; j<5; j++) {taMap[ptMap++] = (pgm_read_byte(&tt[5*i+j]));} \
0x3e,0x41,0x49,0x49,0x3a, 0x7f,0x08,0x08,0x08,0x7f, // G,H taMap[i++]=0;
0x00,0x00,0x7f,0x00,0x00, 0x21,0x41,0x41,0x41,0x3f, // I,J
0x7f,0x08,0x14,0x22,0x41, 0x7f,0x40,0x40,0x40,0x40, // K,L void SetupOledMap() {
0x7f,0x02,0x04,0x02,0x7f, 0x7f,0x04,0x08,0x10,0x7f, // M,N for (byte i=0; i<sizeof (taInitOled); i++) {
0x3e,0x41,0x41,0x41,0x3e, 0x7f,0x11,0x11,0x11,0x0e, // O,P Start(); Write (Adr); Write(0);
0x3e,0x41,0x49,0x51,0x7e, 0x7f,0x09,0x11,0x29,0x46, // Q,R Write (taInitOled[i]); Stop();
0x46,0x49,0x49,0x49,0x32, 0x01,0x01,0x7f,0x01,0x01, // S,T }
0x3f,0x40,0x40,0x40,0x3f, 0x07,0x18,0x60,0x18,0x07, // U,V Clear(); //Sprite (smile);
0x1f,0x60,0x1e,0x60,0x1f, 0x63,0x14,0x08,0x14,0x63, // W,X Show();
0x07,0x04,0x78,0x04,0x07, 0x61,0x51,0x49,0x45,0x43, // Y,Z }
0x00,0x7f,0x41,0x41,0x00, 0x03,0x06,0x1c,0x30,0x60, // [ backsl
0x00,0x41,0x41,0x7f,0x00, 0x04,0x02,0x01,0x02,0x04, // ] ^ //===============================================================
0x80,0x80,0x80,0x80,0x80}; // _ Routine "OledCarMap.h" Copy car and text in buffer
const uint8_t taMin [] PROGMEM = { OledI2C.bmp
0x00,0x03,0x06,0x00, 0x20,0x54,0x54,0x78, // ` a 0x38,0x44,0x44,0x7C, void Error();
0x7f,0x44,0x44,0x38, 0x38,0x44,0x44,0x28, // b c
0x38,0x44,0x44,0x7f, 0x38,0x54,0x54,0x58, // d e void DoubleH () {Cmd (0xda);Cmd (0x02);}
0x00,0xfe,0x09,0x08, 0x9c,0xa2,0xa2,0x7c, // f g
0x7f,0x04,0x04,0x78, 0x00,0x7d,0x00,0x00, // h i void Car(char cc) {
0x40,0x80,0x80,0x7d, 0x7e,0x10,0x28,0x44, // j k cc&=0x7F;
0x00,0x3f,0x40,0x00, 0x7c,0x08,0x08,0x7c, // l m switch (cc/32) {
0x7c,0x08,0x10,0x7c, 0x38,0x44,0x44,0x38, // n o case 0:
0xfc,0x24,0x24,0x18, 0x38,0x44,0x44,0xf8, // p q if(cc=13) {SetLine(saveLi+1);SetCol(0);} // saut de ligne
0x7c,0x04,0x04,0x08, 0x48,0x54,0x54,0x24, // r s break;
0x04,0x04,0x7c,0x04, 0x3c,0x40,0x40,0x3c, // t u case 1: // codes 32-
0x1c,0x60,0x60,0x1c, 0x5c,0x20,0x20,0x5c, // v w for (byte i=0; i<4; i++)
0x64,0x18,0x18,0x64, 0x04,0x08,0x78,0x04, // x y { taMap[ptMap++] = pgm_read_byte(&taNum[((cc-32)*4)+i]); }
0x64,0x54,0x4C,0x44, 0x08,0x08,0x36,0x41, // z { taMap[ptMap++] = 0; taMap[ptMap++] = 0;
0x00,0x00,0xff,0x00, 0x41,0x36,0x08,0x08, // | } break;
0x10,0x20,0x10,0x20, 0xff,0xff,0xff,0xff}; // ~ del case 2: // codes 64-
const uint8_t smile[] PROGMEM = {0x3c,0x42,0x95,0xa5,0xa1,0xa1, 0xa5,0x95,0x42 for (byte i=0; i<5; i++)
const uint8_t sad [] PROGMEM = {0x3c,0x42,0xc5,0xa5,0xa1,0xa1, 0xa5,0xc5,0x42 { taMap[ptMap++] = (pgm_read_byte(&taMaj[((cc-64)*5)+i])); }
const uint8_t didel[] PROGMEM = {0x82,0xf2,0xfe,0xfe,0x8e,0x82,0xc2,0x3c,0x00, taMap[ptMap++] = 0;
0xc0,0xf8,0xfd,0x3d,0x0d,0x00, \ break;
0x82,0xf2,0xfe,0xfe,0x8e,0x82,0xc2,0x3c,0x00, \ case 3: //codes 96-
0xc0,0xf8,0xfe,0xfe,0x96,0x92,0x82,0x02,0x00, \ for (byte i=0; i<4; i++)
0xc0,0xf8,0xfe,0xfe,0x86,0x80,0x80,0x80,0x80 }; { taMap[ptMap++] = (pgm_read_byte(&taMin[((cc-96)*4)+i])); }
taMap[ptMap++] = 0;
//=============================================================== break;
}
Routine "OledControlMap.h" 170429 }
// Initialisation and transfer
void Cmd (byte cc) { #define Text(tt) \
Start(); Write (Adr); Write(0);Write (cc); Stop(); for (byte i=0; i<sizeof tt; i++) \
} { Car (tt[i]); }
void Cmd2 (byte aa,byte bb) {
Start(); Write (Adr); Write(0);Write (aa); Write (bb);Stop(); void Error() {
} LiCol(0,100); Car('e');Car('r');Car('r');Car('o');Car('r');
void Clear(); void Show(); }
byte taInitOled[]={ 0xae, 0xd5, 0x80, 0xa8, 63, \ //===============================================================
0xD3, 0x0, 0x40, 0x8d, 0x14, 0x20, 0x00, 0xa1, \
0xc8, 0xDA, 0x12, 0x81, 0xcf, 0xd9, 0xf1, 0xdb, \
Routine OledNum.h display non significative zeros
0x40, 0xa4, 0xa6, 0x2e, 0xaf }; void Bin8 (byte bb) {
for (byte i=0;i<8;i++) {
uint16_t ptMap; if (bb&0x80) Car('1');
uint8_t taMap[1024]; else Car('0');
void Clear() { //nn<128x8=1024 bb <<= 1;
for (int i=0; i<1024; i++) {taMap[i]=0;} }
} Car(' ');
void ClearRight() { //nn<128x8=1024 }
for (int i=0; i<1024; i++) { char ConvNibble (byte nn) { // converti 4 bit hexa en Ascii
if (i&0x40) {taMap[i]=0;} // 64..127 byte cc;
} if (nn<10) {cc = nn + '0';}
} else {cc = nn-10 + 'A';}
void Fill(byte li,byte co,byte ll,byte dd) { return cc;
ptMap = 128*li+co; }
for (int i=0; i<ll; i++) {taMap[ptMap+i]=0;} void Hex8 (byte hh) {
} byte cc;
cc = ConvNibble (hh >> 4) ; // ne modifie pas hh
void Show () { // include Initransfert Car(cc);
Start(); Write (Adr); Write(0); cc = ConvNibble (hh & 0x0F) ;
Write (0x21); Write (0); Write (127); Car(cc);
Write (0x22); Write (0); Write (7); Car(' '); // space
Stop(); }
Start(); Write (Adr); Write (0x40); void Hex16 (uint16_t hh) {
for (int i=0; i<1024; i++) byte cc;
{ Write (taMap[i]);} cc = ConvNibble (hh >> 12) ; Car(cc);
Stop(); cc = ConvNibble ((hh >> 8)&0x0F) ; Car(cc);
Cmd(0xC8); // patch pour bb! cc = ConvNibble ((hh >> 4)&0x0F) ; Car(cc);
1
C:\Users\jdn\Desktop\GithubJDN\Oled\OledMap_ino.asm
cc = ConvNibble (hh & 0x0F) ; Car(cc); case 1: // codes 32-
Car(' '); tmp = pgm_read_byte(&taNum[((cc-32)*4)+i]);
} tmp &= 0x0f; // low byte
void Hex12 (uint16_t hh) { tmp = nToB[tmp];
byte cc=0; if (i>3) tmp=0;
cc = ConvNibble ((hh >> 8)&0x0F) ; Car(cc); // on écrit ce byte sur 2 colonnes
cc = ConvNibble ((hh >> 4)&0x0F) ; Car(cc); taMap[ptMap++]=(tmp); taMap[ptMap++]=(tmp);
cc = ConvNibble (hh & 0x0F) ; Car(cc); break;
Car(' '); case 2: // codes 64-
} tmp = pgm_read_byte(&taMaj[((cc-64)*5)+i]);
uint16_t BinDec8 (uint8_t bb) { tmp &= 0x0f; // low byte
uint16_t dd=0; tmp = nToB[tmp];
for (byte i=0; i<8; i++) { taMap[ptMap++] = (tmp); taMap[ptMap++] = (tmp);
if ((dd & 0x0F)>0x04) {dd += 0x03;} break;
if ((dd & 0xF0)>0x40) {dd += 0x30;} case 3: // codes 96-
dd=dd<<1; tmp = pgm_read_byte(&taMin[((cc-96)*4)+i]);
if ((bb & 0x80)) {dd += 1;} //inject bit tmp &= 0x0f; // low byte
bb=bb<<1; // prepare next bit tmp = nToB[tmp];
} // on écrit ce byte sur 2 colonnes
return dd; taMap[ptMap++] = (tmp); taMap[ptMap++] = (tmp);
} break;
void Dec8 (byte hh) { } // end switch
Hex12(BinDec8(hh)); } // end for
} // On ajoute 2 espaces
uint16_t BinDec9999 (uint16_t bb) { //0x270F max taMap[ptMap++] = (0);taMap[ptMap++] = (0);
uint16_t dd=0; // on s'occupe des nible inf
for (byte i=0; i<16; i++) { SetLine (++saveLi); SetCol(saveCol);
if ((dd & 0x000F)>0x0004) {dd += 0x0003;} for (byte i=0; i<k; i++) {
if ((dd & 0x00F0)>0x0040) {dd += 0x0030;} switch (cc/32) {
if ((dd & 0x0F00)>0x0400) {dd += 0x0300;} case 0:
if ((dd & 0xF000)>0x4000) {dd += 0x3000;} break;
dd=dd<<1; case 1: // codes 32-
if ((bb & 0x8000)) {dd += 1; } //inject bit tmp = pgm_read_byte(&taNum[((cc-32)*4)+i]);
bb<<=1; // prepare next bit tmp = (tmp&0xf0)>>4 ; // high byte
} tmp = nToB[tmp];
return dd; if (i>3) tmp=0;
} // on écrit ce byte sur 2 colonnes
void Dec9999 (uint16_t hh) { // limit� � 0x2703 taMap[ptMap++] = (tmp); taMap[ptMap++] = (tmp);
if (hh>9999) { Car('?'); Car('?'); Car('?'); Car('?'); } break;
else Hex16(BinDec9999(hh)); case 2: // codes 64-
} tmp = pgm_read_byte(&taMaj[((cc-64)*5)+i]);
//=============================================================== tmp = (tmp&0xf0)>>4 ; // high byte
Routine "OledGraMap.h" Dots and simple lines in buffer 170426 tmp = nToB[tmp];
// on écrit ce byte sur 2 colonnes
void Dot(byte xx,byte yy) { // yy 0-64 --> 0-7 taMap[ptMap++]=(tmp); taMap[ptMap++]=(tmp);
byte coly, nob; break;
coly = yy/8; nob = yy%8; case 3: // codes 96-
saveLi = yy/8; saveCol = xx+1; tmp = pgm_read_byte(&taMin[((cc-96)*4)+i]);
ptMap = (128*saveLi)+saveCol; tmp = (tmp&0xf0)>>4 ; // high byte
// GetLiCol(); tmp = nToB[tmp];
taMap[(coly*128)+xx] |= (1<<nob); // on écrit ce byte sur 2 colonnes
} taMap[ptMap++]=(tmp); taMap[ptMap++]=(tmp);
void NoDot(byte xx,byte yy) { // yy 0-64 --> 0-7 break;
byte coly, nob; } // end switch
coly = yy/8; nob = yy%8; } // end for
saveLi = yy/8; saveCol = xx+1; // On ajoute 2 espaces
ptMap = (128*saveLi)+saveCol; taMap[ptMap++] = (0);taMap[ptMap++] = (0);
// GetLiCol(); //if (cc&(1<<5)) saveCol+=10; else saveCol+=12; // prep car suivant
taMap[(coly*128)+xx] &= ~(1<<nob); saveCol+=12;
} SetCol(saveCol);
void DDot(byte xx,byte yy) { // yy0-64 --> 0-7 }
byte coly, nob; // on ajoute un point en dessous void Space (byte nn){ saveCol+=nn; SetCol(saveCol); }
coly = yy/8; nob = yy%8;
taMap[(coly*128)+xx] |= (1<<nob); void BigBin8 (byte bb) {
if ((nob==7)&&(coly<7)) { coly++; nob=0; } for (byte i=0;i<8;i++) {
else { nob++; } if (bb&0x80) Big('1');
taMap[(coly*128)+xx] |= (1<<nob); else Big('0');
} bb <<= 1;
void Hline (byte yy) { }
for (byte i=0; i<128; i++) { // Big(' ');
// taMap[(yy*128)+i] |= (1<<(yy%8)); }
Dot(i,yy); void BigHex8 (byte hh) {
} byte cc;
} cc = ConvNibble (hh >> 4) ; // ne modifie pas hh
void Hseg (byte xx,byte yy,byte ll) { Big(cc);
for (byte i=0; i<ll; i++) { cc = ConvNibble (hh & 0x0F) ;
if((xx+i)>127) break; Big(cc);
Dot(xx+i,yy); // Big(' '); // space
} }
} void BigHex16 (uint16_t hh) {
void Vline (byte xx) { byte cc;
for (byte i=0; i<8; i++) { cc = ConvNibble (hh >> 12) ; Big(cc);
taMap[(i*128)+xx] = 0xff; cc = ConvNibble ((hh >> 8)&0x0F) ; Big(cc);
} cc = ConvNibble ((hh >> 4)&0x0F) ; Big(cc);
} cc = ConvNibble (hh & 0x0F) ; Big(cc);
void Vseg (byte xx,byte yy,byte hh) { // Big(' ');
for (byte i=0; i<hh; i++) { }
if((yy+i)>63) break; void BigHex12 (uint16_t hh) {
NoDot (xx,yy+i); byte cc=0;
} cc = ConvNibble ((hh >> 8)&0x0F) ; Big(cc);
for (byte i=0; i<hh; i++) { cc = ConvNibble ((hh >> 4)&0x0F) ; Big(cc);
if((yy+i)>63) break; cc = ConvNibble (hh & 0x0F) ; Big(cc);
Dot (xx,yy+i); // Big(' ');
} }
}
void BigDec8 (byte hh) { BigHex12(BinDec8(hh)); }
//===========
void BigDec9999 (uint16_t hh) { // limité à 0x270F
Routine "OledBig.h" Double size single Ascii character and numbers if (hh>9999) { Big('?'); Big('?'); Big('?'); Big('?'); }
// Table to double nibble to byte else BigHex16(BinDec9999(hh));
byte nToB[]={0,3,0xc,0xf,0x30,0x33,0x3c,0x3f,0xc0,0xc3,0xcc,0xcf,0xf0,0xf3,0xf }
void Big(byte cc) {
//utilise saveLi -/> saveCol -->+8 ou+10 selon cc&(1<<5) //=========================
cc&=0x7F; byte tmp,i,k;
//if (cc&(1<<5)) k=4; else k=5; // taille Routine "OledLineCircle.h" 170603
k=5; int sx,sy;
// on s'occupe des nible sup void Line(int8_t x0,int8_t y0,int8_t x1,int8_t y1){
SetLine (--saveLi); // saveCol défini au premier car int8_t dx = abs(x1-x0), sx = x0<x1 ? 1 : -1;
for (byte i=0; i<k; i++) { int8_t dy = -abs(y1-y0), sy = y0<y1 ? 1 : -1;
switch (cc/32) { int8_t err = dx+dy, e2; /* error value e_xy */
case 0: while(1){
Error(); Dot(x0,y0);
break; if (x0==x1 && y0==y1) break;
2
C:\Users\jdn\Desktop\GithubJDN\Oled\OledMap_ino.asm
e2 = 2*err;
if (e2 > dy) { err += dy; x0 += sx; } /* e_xy+e_x > 0 */
if (e2 < dx) { err += dx; y0 += sy; } /* e_xy+e_y < 0 */
}
} // End Line
void Circle(uint8_t x0,uint8_t y0,uint8_t radius) {
int8_t f = 1 - radius;
int8_t ddF_x = 0;
int8_t ddF_y = -2 * radius;
uint8_t x = 0;
uint8_t y = radius;
Dot(x0, y0 + radius);
Dot(x0, y0 - radius);
Dot(x0 + radius, y0);
Dot(x0 - radius, y0);
while(x < y) {
if(f >= 0) {
y--; ddF_y += 2; f += ddF_y;
}
x++; ddF_x += 2; f += ddF_x + 1;
Dot(x0+x,y0+y); Dot(x0-x,y0+y);
Dot(x0+x,y0-y); Dot(x0-x,y0-y);
Dot(x0+y,y0+x); Dot(x0-y,y0+x);
Dot(x0+y,y0-x); Dot(x0-y,y0-x);
}
} // end Circle