repo

Dependencies:   mbed BLE_API nRF51822 X_NUCLEO_IDB0XA1

Committer:
orshefi
Date:
Thu Oct 31 18:50:07 2019 +0000
Revision:
81:b26ba1ec7625
Parent:
80:4fbfa09ac26c
init

Who changed what in which revision?

UserRevisionLine numberNew contents of line
orshefi 80:4fbfa09ac26c 1 #include "fonts.h"
orshefi 80:4fbfa09ac26c 2 #include "mbed.h"
orshefi 80:4fbfa09ac26c 3 #include "ble/BLE.h"
orshefi 80:4fbfa09ac26c 4 #include <stdbool.h>
orshefi 80:4fbfa09ac26c 5 #include <stdint.h>
orshefi 80:4fbfa09ac26c 6
orshefi 80:4fbfa09ac26c 7
orshefi 80:4fbfa09ac26c 8 DigitalOut SCLK(P0_8);
orshefi 80:4fbfa09ac26c 9 DigitalOut SDIN(P0_10);
orshefi 80:4fbfa09ac26c 10 DigitalOut RES(P0_18);
orshefi 80:4fbfa09ac26c 11 DigitalOut CS(P0_29);
orshefi 80:4fbfa09ac26c 12 DigitalOut DC(P0_28);
orshefi 80:4fbfa09ac26c 13
orshefi 80:4fbfa09ac26c 14 #define Max_Column 160
orshefi 80:4fbfa09ac26c 15 #define Max_Row 136
orshefi 80:4fbfa09ac26c 16 #define Brightness 0xcf
orshefi 80:4fbfa09ac26c 17
orshefi 80:4fbfa09ac26c 18 void oledwrite(int num1,int num2,int num3, int analog_read);
orshefi 80:4fbfa09ac26c 19
orshefi 80:4fbfa09ac26c 20 int num1;
orshefi 80:4fbfa09ac26c 21 int num2;
orshefi 80:4fbfa09ac26c 22 int num3;
orshefi 80:4fbfa09ac26c 23
orshefi 80:4fbfa09ac26c 24
orshefi 80:4fbfa09ac26c 25 void part_num(int analog_read)
orshefi 80:4fbfa09ac26c 26 {
orshefi 80:4fbfa09ac26c 27 for(int q = 0;q<=3;q++)
orshefi 80:4fbfa09ac26c 28 {
orshefi 80:4fbfa09ac26c 29 int num = analog_read;
orshefi 80:4fbfa09ac26c 30 for(int k = 0;k<3;k++)
orshefi 80:4fbfa09ac26c 31 {
orshefi 80:4fbfa09ac26c 32 switch(k)
orshefi 80:4fbfa09ac26c 33 {
orshefi 80:4fbfa09ac26c 34 case 0:
orshefi 80:4fbfa09ac26c 35 num3 = (num%10);
orshefi 80:4fbfa09ac26c 36 num = num/10;
orshefi 80:4fbfa09ac26c 37 break;
orshefi 80:4fbfa09ac26c 38 case 1:
orshefi 80:4fbfa09ac26c 39 num2 = (num%10);
orshefi 80:4fbfa09ac26c 40 num = num/10;
orshefi 80:4fbfa09ac26c 41 break;
orshefi 80:4fbfa09ac26c 42 case 2:
orshefi 80:4fbfa09ac26c 43 num1 = (num%10);
orshefi 80:4fbfa09ac26c 44 num = num/10;
orshefi 80:4fbfa09ac26c 45 break;
orshefi 80:4fbfa09ac26c 46 }
orshefi 80:4fbfa09ac26c 47 }
orshefi 80:4fbfa09ac26c 48 }
orshefi 80:4fbfa09ac26c 49 oledwrite(num1,num2,num3,analog_read);
orshefi 80:4fbfa09ac26c 50 }
orshefi 80:4fbfa09ac26c 51
orshefi 80:4fbfa09ac26c 52 void Write_Command(unsigned char Data)
orshefi 80:4fbfa09ac26c 53 {
orshefi 80:4fbfa09ac26c 54 unsigned char i;
orshefi 80:4fbfa09ac26c 55
orshefi 80:4fbfa09ac26c 56 CS=0;
orshefi 80:4fbfa09ac26c 57 DC=0;
orshefi 80:4fbfa09ac26c 58 for (i=0; i<8; i++)
orshefi 80:4fbfa09ac26c 59 {
orshefi 80:4fbfa09ac26c 60 SCLK=0;
orshefi 80:4fbfa09ac26c 61 SDIN=(Data&0x80)>>7;
orshefi 80:4fbfa09ac26c 62 Data = Data << 1;
orshefi 80:4fbfa09ac26c 63 SCLK=1;
orshefi 80:4fbfa09ac26c 64 }
orshefi 80:4fbfa09ac26c 65 DC=1;
orshefi 80:4fbfa09ac26c 66 CS=1;
orshefi 80:4fbfa09ac26c 67 }
orshefi 80:4fbfa09ac26c 68
orshefi 80:4fbfa09ac26c 69
orshefi 80:4fbfa09ac26c 70 void Write_Data(unsigned char Data)
orshefi 80:4fbfa09ac26c 71 {
orshefi 80:4fbfa09ac26c 72 unsigned char i;
orshefi 80:4fbfa09ac26c 73
orshefi 80:4fbfa09ac26c 74 CS=0;
orshefi 80:4fbfa09ac26c 75 DC=1;
orshefi 80:4fbfa09ac26c 76 for (i=0; i<8; i++)
orshefi 80:4fbfa09ac26c 77 {
orshefi 80:4fbfa09ac26c 78 SCLK=0;
orshefi 80:4fbfa09ac26c 79 SDIN=(Data&0x80)>>7;
orshefi 80:4fbfa09ac26c 80 Data = Data << 1;
orshefi 80:4fbfa09ac26c 81 SCLK=1;
orshefi 80:4fbfa09ac26c 82 }
orshefi 80:4fbfa09ac26c 83 DC=1;
orshefi 80:4fbfa09ac26c 84 CS=1;
orshefi 80:4fbfa09ac26c 85 }
orshefi 80:4fbfa09ac26c 86
orshefi 80:4fbfa09ac26c 87
orshefi 80:4fbfa09ac26c 88 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
orshefi 80:4fbfa09ac26c 89 // Instruction Setting
orshefi 80:4fbfa09ac26c 90 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
orshefi 80:4fbfa09ac26c 91 void Set_Start_Column(unsigned char d)
orshefi 80:4fbfa09ac26c 92 {
orshefi 80:4fbfa09ac26c 93 Write_Command(0x00+d%16); // Set Lower Column Start Address for Page Addressing Mode
orshefi 80:4fbfa09ac26c 94 // Default => 0x00
orshefi 80:4fbfa09ac26c 95 Write_Command(0x10+d/16); // Set Higher Column Start Address for Page Addressing Mode
orshefi 80:4fbfa09ac26c 96 // Default => 0x10
orshefi 80:4fbfa09ac26c 97 }
orshefi 80:4fbfa09ac26c 98
orshefi 80:4fbfa09ac26c 99
orshefi 80:4fbfa09ac26c 100 void Set_Page_Addressing_Mode(void)
orshefi 80:4fbfa09ac26c 101 {
orshefi 80:4fbfa09ac26c 102 Write_Command(0x20); // Set Memory Page Addressing Mode
orshefi 80:4fbfa09ac26c 103 }
orshefi 80:4fbfa09ac26c 104
orshefi 80:4fbfa09ac26c 105 void Set_Vertical_Addressing_Mode(void)
orshefi 80:4fbfa09ac26c 106 {
orshefi 80:4fbfa09ac26c 107 Write_Command(0x21); // Set Memory Vertical Addressing Mode
orshefi 80:4fbfa09ac26c 108 }
orshefi 80:4fbfa09ac26c 109
orshefi 80:4fbfa09ac26c 110 void Set_Contrast_Control(unsigned char d)
orshefi 80:4fbfa09ac26c 111 {
orshefi 80:4fbfa09ac26c 112 Write_Command(0x81); // Set Contrast Control
orshefi 80:4fbfa09ac26c 113 Write_Command(d); // Default => 0x7F
orshefi 80:4fbfa09ac26c 114 }
orshefi 80:4fbfa09ac26c 115
orshefi 80:4fbfa09ac26c 116 void Set_Segment_Remap(unsigned char d)
orshefi 80:4fbfa09ac26c 117 {
orshefi 80:4fbfa09ac26c 118 Write_Command(d); // Set Segment Re-Map
orshefi 80:4fbfa09ac26c 119 // Default => 0xA0
orshefi 80:4fbfa09ac26c 120 // 0xA0 => Column Address 0 Mapped to SEG0
orshefi 80:4fbfa09ac26c 121 // 0xA1 => Column Address 0 Mapped to SEG127
orshefi 80:4fbfa09ac26c 122 }
orshefi 80:4fbfa09ac26c 123
orshefi 80:4fbfa09ac26c 124 void Set_Entire_Display(unsigned char d)
orshefi 80:4fbfa09ac26c 125 {
orshefi 80:4fbfa09ac26c 126 Write_Command(d); // Set Entire Display On / Off
orshefi 80:4fbfa09ac26c 127 // Default => 0xA4
orshefi 80:4fbfa09ac26c 128 // 0xA4 => Normal Display
orshefi 80:4fbfa09ac26c 129 // 0xA5 => Entire Display On
orshefi 80:4fbfa09ac26c 130 }
orshefi 80:4fbfa09ac26c 131
orshefi 80:4fbfa09ac26c 132 void Set_Inverse_Display(unsigned char d)
orshefi 80:4fbfa09ac26c 133 {
orshefi 80:4fbfa09ac26c 134 Write_Command(d); // Set Inverse Display On/Off
orshefi 80:4fbfa09ac26c 135 // Default => 0xA6
orshefi 80:4fbfa09ac26c 136 // 0xA6 => Normal Display
orshefi 80:4fbfa09ac26c 137 // 0xA7 => Inverse Display On
orshefi 80:4fbfa09ac26c 138 }
orshefi 80:4fbfa09ac26c 139
orshefi 80:4fbfa09ac26c 140 void Set_DCDC_Control_Mode(unsigned char d)
orshefi 80:4fbfa09ac26c 141 {
orshefi 80:4fbfa09ac26c 142 Write_Command(0xad); //Set DC-DC Control Mode
orshefi 80:4fbfa09ac26c 143 Write_Command(d); //DC-DC Setting Mode Set
orshefi 80:4fbfa09ac26c 144 }
orshefi 80:4fbfa09ac26c 145
orshefi 80:4fbfa09ac26c 146 void Set_Display_On_Off(unsigned char d)
orshefi 80:4fbfa09ac26c 147 {
orshefi 80:4fbfa09ac26c 148 Write_Command(d); // Set Display On/Off
orshefi 80:4fbfa09ac26c 149 // Default => 0xAE
orshefi 80:4fbfa09ac26c 150 // 0xAE => Display Off
orshefi 80:4fbfa09ac26c 151 // 0xAF => Display On
orshefi 80:4fbfa09ac26c 152 }
orshefi 80:4fbfa09ac26c 153
orshefi 80:4fbfa09ac26c 154 void Set_Page_Address(unsigned char d)
orshefi 80:4fbfa09ac26c 155 {
orshefi 80:4fbfa09ac26c 156 Write_Command(0xb0); // Set Page Address
orshefi 80:4fbfa09ac26c 157 Write_Command(d); // Page Address
orshefi 80:4fbfa09ac26c 158 }
orshefi 80:4fbfa09ac26c 159
orshefi 80:4fbfa09ac26c 160 void Set_Common_Remap(unsigned char d)
orshefi 80:4fbfa09ac26c 161 {
orshefi 80:4fbfa09ac26c 162 Write_Command(d); // Set COM Output Scan Direction
orshefi 80:4fbfa09ac26c 163 // Default => 0xC0
orshefi 80:4fbfa09ac26c 164 // 0xC0 => Scan from COM0 to COM[N-1]
orshefi 80:4fbfa09ac26c 165 // 0xC8 => Scan from COM[N-1] to COM0
orshefi 80:4fbfa09ac26c 166 }
orshefi 80:4fbfa09ac26c 167
orshefi 80:4fbfa09ac26c 168 void Set_Display_Resolution(unsigned char d)
orshefi 80:4fbfa09ac26c 169 {
orshefi 80:4fbfa09ac26c 170 Write_Command(0xa9); //Set Display Resolution Command
orshefi 80:4fbfa09ac26c 171 Write_Command(d); //00= 64 COM⊙ 160 SEG
orshefi 80:4fbfa09ac26c 172 //01= 96 COM⊙ 160 SEG
orshefi 80:4fbfa09ac26c 173 //02=128 COM⊙ 160 SEG
orshefi 80:4fbfa09ac26c 174 //03=160 COM⊙ 160 SEG
orshefi 80:4fbfa09ac26c 175 }
orshefi 80:4fbfa09ac26c 176
orshefi 80:4fbfa09ac26c 177 void Set_Display_Clock(unsigned char d)
orshefi 80:4fbfa09ac26c 178 {
orshefi 80:4fbfa09ac26c 179 Write_Command(0xD5); // Set Display Clock Divide Ratio / Oscillator Frequency
orshefi 80:4fbfa09ac26c 180 Write_Command(d); // Default => 0x50
orshefi 80:4fbfa09ac26c 181 // D[3:0] => Display Clock Divider
orshefi 80:4fbfa09ac26c 182 // D[7:4] => Oscillator Frequency
orshefi 80:4fbfa09ac26c 183 }
orshefi 80:4fbfa09ac26c 184
orshefi 80:4fbfa09ac26c 185 void Set_Precharge_Period(unsigned char d)
orshefi 80:4fbfa09ac26c 186 {
orshefi 80:4fbfa09ac26c 187 Write_Command(0xD9); // Set Pre-Charge Period
orshefi 80:4fbfa09ac26c 188 Write_Command(d); // Default => 0x22 (2 Display Clocks [Phase 2] / 2 Display Clocks [Phase 1])
orshefi 80:4fbfa09ac26c 189 // D[3:0] => Phase 1 Period in 1~15 Display Clocks
orshefi 80:4fbfa09ac26c 190 // D[7:4] => Phase 2 Period in 1~15 Display Clocks
orshefi 80:4fbfa09ac26c 191 }
orshefi 80:4fbfa09ac26c 192
orshefi 80:4fbfa09ac26c 193 void Set_VCOMH(unsigned char d)
orshefi 80:4fbfa09ac26c 194 {
orshefi 80:4fbfa09ac26c 195 Write_Command(0xDB); // Set VCOMH Deselect Level
orshefi 80:4fbfa09ac26c 196 Write_Command(d); // Default => 0x35 (VCOMH = 1 x VREF )
orshefi 80:4fbfa09ac26c 197 }
orshefi 80:4fbfa09ac26c 198
orshefi 80:4fbfa09ac26c 199 void Set_VSEGH(unsigned char d)
orshefi 80:4fbfa09ac26c 200 {
orshefi 80:4fbfa09ac26c 201 Write_Command(0xDC); // Set VSEGH Deselect Level
orshefi 80:4fbfa09ac26c 202 Write_Command(d); // Default => 0x35 (VSEGH = 1 x VREF )
orshefi 80:4fbfa09ac26c 203 }
orshefi 80:4fbfa09ac26c 204
orshefi 80:4fbfa09ac26c 205 void Set_VSL(unsigned char d)
orshefi 80:4fbfa09ac26c 206 {
orshefi 80:4fbfa09ac26c 207 Write_Command(d); // Set VSL
orshefi 80:4fbfa09ac26c 208 // Default => 0x30
orshefi 80:4fbfa09ac26c 209 }
orshefi 80:4fbfa09ac26c 210
orshefi 80:4fbfa09ac26c 211 void Read_Modify_Write_Start(void)
orshefi 80:4fbfa09ac26c 212 {
orshefi 80:4fbfa09ac26c 213 Write_Command(0xe0); //Read-Modify-Write Start
orshefi 80:4fbfa09ac26c 214 }
orshefi 80:4fbfa09ac26c 215
orshefi 80:4fbfa09ac26c 216 void Read_Modify_Write_End(void)
orshefi 80:4fbfa09ac26c 217 {
orshefi 80:4fbfa09ac26c 218 Write_Command(0xee); //Read-Modify-Write End
orshefi 80:4fbfa09ac26c 219 }
orshefi 80:4fbfa09ac26c 220
orshefi 80:4fbfa09ac26c 221 void Set_NOP()
orshefi 80:4fbfa09ac26c 222 {
orshefi 80:4fbfa09ac26c 223 Write_Command(0xE3); // Command for No Operation
orshefi 80:4fbfa09ac26c 224 }
orshefi 80:4fbfa09ac26c 225
orshefi 80:4fbfa09ac26c 226
orshefi 80:4fbfa09ac26c 227
orshefi 80:4fbfa09ac26c 228 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
orshefi 80:4fbfa09ac26c 229 // Show Character (5x7)
orshefi 80:4fbfa09ac26c 230 //
orshefi 80:4fbfa09ac26c 231 // a: Database
orshefi 80:4fbfa09ac26c 232 // b: Ascii
orshefi 80:4fbfa09ac26c 233 // c: Start Page
orshefi 80:4fbfa09ac26c 234 // d: Start Column
orshefi 80:4fbfa09ac26c 235 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
orshefi 80:4fbfa09ac26c 236 void Show_Font_big(unsigned char a, unsigned char b, unsigned char c, unsigned char d)
orshefi 80:4fbfa09ac26c 237 {
orshefi 80:4fbfa09ac26c 238 unsigned char i;
orshefi 80:4fbfa09ac26c 239
orshefi 80:4fbfa09ac26c 240 Set_Page_Address(c);
orshefi 80:4fbfa09ac26c 241 Set_Start_Column(d);
orshefi 80:4fbfa09ac26c 242
orshefi 80:4fbfa09ac26c 243 for(i=0;i<11;i++)
orshefi 80:4fbfa09ac26c 244 {
orshefi 80:4fbfa09ac26c 245 Write_Data(Shefi[b-1][i]);
orshefi 80:4fbfa09ac26c 246 }
orshefi 80:4fbfa09ac26c 247 Write_Data(0x00);
orshefi 80:4fbfa09ac26c 248 }
orshefi 80:4fbfa09ac26c 249
orshefi 80:4fbfa09ac26c 250 void Show_Font_num(unsigned char a, unsigned char b, unsigned char c, unsigned char d)
orshefi 80:4fbfa09ac26c 251 {
orshefi 80:4fbfa09ac26c 252 unsigned int i;
orshefi 80:4fbfa09ac26c 253
orshefi 80:4fbfa09ac26c 254 Set_Page_Address(c);
orshefi 80:4fbfa09ac26c 255 Set_Start_Column(d);
orshefi 80:4fbfa09ac26c 256
orshefi 80:4fbfa09ac26c 257 for(i=0;i<22;i++)
orshefi 80:4fbfa09ac26c 258 {
orshefi 80:4fbfa09ac26c 259 Write_Data(Shefinum[b-1][i]);
orshefi 80:4fbfa09ac26c 260 }
orshefi 80:4fbfa09ac26c 261 Write_Data(0x00);
orshefi 80:4fbfa09ac26c 262 }
orshefi 80:4fbfa09ac26c 263
orshefi 80:4fbfa09ac26c 264
orshefi 80:4fbfa09ac26c 265 void Show_Font57(unsigned char a, unsigned char b, unsigned char c, unsigned char d)
orshefi 80:4fbfa09ac26c 266 {
orshefi 80:4fbfa09ac26c 267 unsigned char i;
orshefi 80:4fbfa09ac26c 268
orshefi 80:4fbfa09ac26c 269 Set_Page_Address(c);
orshefi 80:4fbfa09ac26c 270 Set_Start_Column(d);
orshefi 80:4fbfa09ac26c 271
orshefi 80:4fbfa09ac26c 272 for(i=0;i<5;i++)
orshefi 80:4fbfa09ac26c 273 {
orshefi 80:4fbfa09ac26c 274 Write_Data(Ascii_1[b-1][i]);
orshefi 80:4fbfa09ac26c 275 }
orshefi 80:4fbfa09ac26c 276 Write_Data(0x00);
orshefi 80:4fbfa09ac26c 277 }
orshefi 80:4fbfa09ac26c 278
orshefi 80:4fbfa09ac26c 279 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
orshefi 80:4fbfa09ac26c 280 // Show String
orshefi 80:4fbfa09ac26c 281 //
orshefi 80:4fbfa09ac26c 282 // a: Database
orshefi 80:4fbfa09ac26c 283 // b: Start Page
orshefi 80:4fbfa09ac26c 284 // c: Start Column
orshefi 80:4fbfa09ac26c 285 // * Must write "0" in the end...
orshefi 80:4fbfa09ac26c 286 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
orshefi 80:4fbfa09ac26c 287 void Show_String_big(unsigned char a, unsigned char *Data_Pointer, unsigned char b, unsigned char c)
orshefi 80:4fbfa09ac26c 288 {
orshefi 80:4fbfa09ac26c 289 unsigned char *Src_Pointer;
orshefi 80:4fbfa09ac26c 290
orshefi 80:4fbfa09ac26c 291 Src_Pointer=Data_Pointer;
orshefi 80:4fbfa09ac26c 292 Show_Font57(1,96,b,c); // No-Break Space
orshefi 80:4fbfa09ac26c 293 // Must be written first before the string start...
orshefi 80:4fbfa09ac26c 294
orshefi 80:4fbfa09ac26c 295 while(1)
orshefi 80:4fbfa09ac26c 296 {
orshefi 80:4fbfa09ac26c 297 Show_Font_big(a,*Src_Pointer,b,c);
orshefi 80:4fbfa09ac26c 298 Src_Pointer++;
orshefi 80:4fbfa09ac26c 299 c+=13;
orshefi 80:4fbfa09ac26c 300 if(*Src_Pointer == 0) break;
orshefi 80:4fbfa09ac26c 301 }
orshefi 80:4fbfa09ac26c 302 }
orshefi 80:4fbfa09ac26c 303
orshefi 80:4fbfa09ac26c 304 void Show_String_num(unsigned char a, unsigned char *Data_Pointer, unsigned char b, unsigned char c)
orshefi 80:4fbfa09ac26c 305 {
orshefi 80:4fbfa09ac26c 306 unsigned char *Src_Pointer;
orshefi 80:4fbfa09ac26c 307
orshefi 80:4fbfa09ac26c 308 Src_Pointer=Data_Pointer;
orshefi 80:4fbfa09ac26c 309 Show_Font57(1,96,b,c); // No-Break Space
orshefi 80:4fbfa09ac26c 310 // Must be written first before the string start...
orshefi 80:4fbfa09ac26c 311
orshefi 80:4fbfa09ac26c 312 while(1)
orshefi 80:4fbfa09ac26c 313 {
orshefi 80:4fbfa09ac26c 314 Show_Font_num(a,*Src_Pointer,b,c);
orshefi 80:4fbfa09ac26c 315 Src_Pointer++;
orshefi 80:4fbfa09ac26c 316 c+=26;
orshefi 80:4fbfa09ac26c 317 if(*Src_Pointer == 0) break;
orshefi 80:4fbfa09ac26c 318 }
orshefi 80:4fbfa09ac26c 319 }
orshefi 80:4fbfa09ac26c 320
orshefi 80:4fbfa09ac26c 321 void Show_String(unsigned char a, unsigned char *Data_Pointer, unsigned char b, unsigned char c)
orshefi 80:4fbfa09ac26c 322 {
orshefi 80:4fbfa09ac26c 323 unsigned char *Src_Pointer;
orshefi 80:4fbfa09ac26c 324
orshefi 80:4fbfa09ac26c 325 Src_Pointer=Data_Pointer;
orshefi 80:4fbfa09ac26c 326 Show_Font57(1,96,b,c); // No-Break Space
orshefi 80:4fbfa09ac26c 327 // Must be written first before the string start...
orshefi 80:4fbfa09ac26c 328
orshefi 80:4fbfa09ac26c 329 while(1)
orshefi 80:4fbfa09ac26c 330 {
orshefi 80:4fbfa09ac26c 331 Show_Font57(a,*Src_Pointer,b,c);
orshefi 80:4fbfa09ac26c 332 Src_Pointer++;
orshefi 80:4fbfa09ac26c 333 c+=6;
orshefi 80:4fbfa09ac26c 334 if(*Src_Pointer == 0) break;
orshefi 80:4fbfa09ac26c 335 }
orshefi 80:4fbfa09ac26c 336 }
orshefi 80:4fbfa09ac26c 337
orshefi 80:4fbfa09ac26c 338
orshefi 80:4fbfa09ac26c 339
orshefi 80:4fbfa09ac26c 340 void OLED_initial(void) //SH1108
orshefi 80:4fbfa09ac26c 341 {
orshefi 80:4fbfa09ac26c 342 unsigned char i,j;
orshefi 80:4fbfa09ac26c 343
orshefi 80:4fbfa09ac26c 344 RES = 1;
orshefi 80:4fbfa09ac26c 345
orshefi 80:4fbfa09ac26c 346 Set_Display_On_Off(0xAE); //Display off
orshefi 80:4fbfa09ac26c 347
orshefi 80:4fbfa09ac26c 348 Set_Contrast_Control(Brightness); //set contrast
orshefi 80:4fbfa09ac26c 349
orshefi 80:4fbfa09ac26c 350 Set_Page_Addressing_Mode(); //Set Memory Page addressing mode
orshefi 80:4fbfa09ac26c 351
orshefi 80:4fbfa09ac26c 352 Set_Segment_Remap(0xA0); //set segment re-map 0xA0 => Column Address 0 Mapped to SEG0
orshefi 80:4fbfa09ac26c 353
orshefi 80:4fbfa09ac26c 354 Set_Entire_Display(0xA4); //set entire display off
orshefi 80:4fbfa09ac26c 355
orshefi 80:4fbfa09ac26c 356 Set_Inverse_Display(0xA6); //set normal display
orshefi 80:4fbfa09ac26c 357
orshefi 80:4fbfa09ac26c 358 Set_DCDC_Control_Mode(0x80); //set DC-DC off
orshefi 80:4fbfa09ac26c 359
orshefi 80:4fbfa09ac26c 360 Set_Common_Remap(0xC0); //set commom output scan direction 0xC0 => Scan from COM0 to COM[N-1]
orshefi 80:4fbfa09ac26c 361
orshefi 80:4fbfa09ac26c 362 Set_Display_Clock(0x60); //set display clock divide ratio/osc frequency
orshefi 80:4fbfa09ac26c 363
orshefi 80:4fbfa09ac26c 364 Set_Precharge_Period(0x47); //set dis-charge/pre-charge period
orshefi 80:4fbfa09ac26c 365
orshefi 80:4fbfa09ac26c 366 Set_VCOMH(0x35); //set VCOM deselect level
orshefi 80:4fbfa09ac26c 367
orshefi 80:4fbfa09ac26c 368 Set_VSEGH(0x35); //set VSEGM deselect level
orshefi 80:4fbfa09ac26c 369
orshefi 80:4fbfa09ac26c 370 Set_VSL(0x30); // SET VSL
orshefi 80:4fbfa09ac26c 371
orshefi 80:4fbfa09ac26c 372 Set_Display_Resolution(0x03); // Set display resolution 03=160 COM⊙ 160 SEG
orshefi 80:4fbfa09ac26c 373
orshefi 80:4fbfa09ac26c 374 for(i=0;i<=16;i++)
orshefi 80:4fbfa09ac26c 375 {
orshefi 80:4fbfa09ac26c 376 Set_Start_Column(0x00); //set column address
orshefi 80:4fbfa09ac26c 377 Set_Page_Address(i); //Set Page Address
orshefi 80:4fbfa09ac26c 378
orshefi 80:4fbfa09ac26c 379 for(j=0;j<Max_Column;j++)
orshefi 80:4fbfa09ac26c 380 {
orshefi 80:4fbfa09ac26c 381 Write_Data(0x00);
orshefi 80:4fbfa09ac26c 382 }
orshefi 80:4fbfa09ac26c 383 }
orshefi 80:4fbfa09ac26c 384
orshefi 80:4fbfa09ac26c 385
orshefi 80:4fbfa09ac26c 386 Set_Display_On_Off(0xAF); //display on
orshefi 80:4fbfa09ac26c 387 }
orshefi 80:4fbfa09ac26c 388
orshefi 80:4fbfa09ac26c 389 void Frame_pattern()//Frame Pattern
orshefi 80:4fbfa09ac26c 390 {
orshefi 80:4fbfa09ac26c 391 unsigned char i,j;
orshefi 80:4fbfa09ac26c 392
orshefi 80:4fbfa09ac26c 393 for(i=0;i<=16;i++)
orshefi 80:4fbfa09ac26c 394 {
orshefi 80:4fbfa09ac26c 395 Set_Start_Column(0x00); //set column address
orshefi 80:4fbfa09ac26c 396 Set_Page_Address(i); //Set Page Address
orshefi 80:4fbfa09ac26c 397
orshefi 80:4fbfa09ac26c 398 for(j=0;j<Max_Column;j++)
orshefi 80:4fbfa09ac26c 399 {
orshefi 80:4fbfa09ac26c 400 Write_Data(FramePic[i*Max_Column+j]);
orshefi 80:4fbfa09ac26c 401 }
orshefi 80:4fbfa09ac26c 402 }
orshefi 80:4fbfa09ac26c 403 }
orshefi 80:4fbfa09ac26c 404
orshefi 80:4fbfa09ac26c 405
orshefi 80:4fbfa09ac26c 406 void clear_screen()
orshefi 80:4fbfa09ac26c 407 {
orshefi 80:4fbfa09ac26c 408 unsigned char clearodd[2] = {41,0};
orshefi 80:4fbfa09ac26c 409 unsigned char cleareven[2] = {42,0};
orshefi 80:4fbfa09ac26c 410 unsigned char clearodd1[2] = {43,0};
orshefi 80:4fbfa09ac26c 411 unsigned char cleareven1[2] = {44,0};
orshefi 80:4fbfa09ac26c 412 unsigned char clearodd2[2] = {41,0};
orshefi 80:4fbfa09ac26c 413 unsigned char cleareven2[2] = {42,0};
orshefi 80:4fbfa09ac26c 414 unsigned char clearodd3[2] = {43,0};
orshefi 80:4fbfa09ac26c 415 unsigned char cleareven3[2] = {44,0};
orshefi 80:4fbfa09ac26c 416 unsigned char clearodd4[2] = {41,0};
orshefi 80:4fbfa09ac26c 417 unsigned char cleareven4[2] = {42,0};
orshefi 80:4fbfa09ac26c 418 unsigned char clearodd5[2] = {43,0};
orshefi 80:4fbfa09ac26c 419 unsigned char cleareven5[2] = {44,0};
orshefi 80:4fbfa09ac26c 420 Show_String_num(2,clearodd,8,45);
orshefi 80:4fbfa09ac26c 421 Show_String_num(2,cleareven,9,45);
orshefi 80:4fbfa09ac26c 422 Show_String_num(2,clearodd1,10,45);
orshefi 80:4fbfa09ac26c 423 Show_String_num(2,cleareven1,11,45);
orshefi 80:4fbfa09ac26c 424 Show_String_num(2,clearodd2,8,71);
orshefi 80:4fbfa09ac26c 425 Show_String_num(2,cleareven2,9,71);
orshefi 80:4fbfa09ac26c 426 Show_String_num(2,clearodd3,10,71);
orshefi 80:4fbfa09ac26c 427 Show_String_num(2,cleareven3,11,71);
orshefi 80:4fbfa09ac26c 428 Show_String_num(2,clearodd4,8,97);
orshefi 80:4fbfa09ac26c 429 Show_String_num(2,cleareven4,9,97);
orshefi 80:4fbfa09ac26c 430 Show_String_num(2,clearodd5,10,97);
orshefi 80:4fbfa09ac26c 431 Show_String_num(2,cleareven5,11,97);
orshefi 80:4fbfa09ac26c 432 Show_String_num(2,clearodd4,8,58);
orshefi 80:4fbfa09ac26c 433 Show_String_num(2,cleareven4,9,58);
orshefi 80:4fbfa09ac26c 434 Show_String_num(2,clearodd5,10,58);
orshefi 80:4fbfa09ac26c 435 Show_String_num(2,cleareven5,11,58);
orshefi 80:4fbfa09ac26c 436 Show_String_num(2,clearodd4,8,84);
orshefi 80:4fbfa09ac26c 437 Show_String_num(2,cleareven4,9,84);
orshefi 80:4fbfa09ac26c 438 Show_String_num(2,clearodd5,10,84);
orshefi 80:4fbfa09ac26c 439 Show_String_num(2,cleareven5,11,84);
orshefi 80:4fbfa09ac26c 440 }
orshefi 80:4fbfa09ac26c 441
orshefi 80:4fbfa09ac26c 442 void oledwrite(int num1,int num2,int num3,int analog_read)
orshefi 80:4fbfa09ac26c 443 {
orshefi 80:4fbfa09ac26c 444 unsigned char sh[8] = {1,3,5,7,9,11,13,0};
orshefi 80:4fbfa09ac26c 445 unsigned char sh1[8] = {2,4,6,8,10,12,14,0};
orshefi 80:4fbfa09ac26c 446 unsigned char Name[4]={54,33,44,0};
orshefi 80:4fbfa09ac26c 447 // unsigned char Name[10]={52,69,77,80,82,65,84,85,82,0};
orshefi 80:4fbfa09ac26c 448 unsigned char dot[2]={14,0};
orshefi 80:4fbfa09ac26c 449 unsigned char a,b,c;
orshefi 80:4fbfa09ac26c 450 Show_String_big(2,sh,4,35);
orshefi 80:4fbfa09ac26c 451 Show_String_big(2,sh1,5,35);
orshefi 80:4fbfa09ac26c 452 Show_String(1,Name,14,75);
orshefi 80:4fbfa09ac26c 453 // Show_String(1,dot,11,95);
orshefi 80:4fbfa09ac26c 454 clear_screen();
orshefi 80:4fbfa09ac26c 455 switch(num1)
orshefi 80:4fbfa09ac26c 456 {
orshefi 80:4fbfa09ac26c 457 case 0:
orshefi 80:4fbfa09ac26c 458 a = 1;
orshefi 80:4fbfa09ac26c 459 break;
orshefi 80:4fbfa09ac26c 460 case 1:
orshefi 80:4fbfa09ac26c 461 a = 5;
orshefi 80:4fbfa09ac26c 462 break;
orshefi 80:4fbfa09ac26c 463 case 2:
orshefi 80:4fbfa09ac26c 464 a = 9;
orshefi 80:4fbfa09ac26c 465 break;
orshefi 80:4fbfa09ac26c 466 case 3:
orshefi 80:4fbfa09ac26c 467 a = 13;
orshefi 80:4fbfa09ac26c 468 break;
orshefi 80:4fbfa09ac26c 469 case 4:
orshefi 80:4fbfa09ac26c 470 a = 17;
orshefi 80:4fbfa09ac26c 471 break;
orshefi 80:4fbfa09ac26c 472 case 5:
orshefi 80:4fbfa09ac26c 473 a = 21;
orshefi 80:4fbfa09ac26c 474 break;
orshefi 80:4fbfa09ac26c 475 case 6:
orshefi 80:4fbfa09ac26c 476 a = 25;
orshefi 80:4fbfa09ac26c 477 break;
orshefi 80:4fbfa09ac26c 478 case 7:
orshefi 80:4fbfa09ac26c 479 a = 29;
orshefi 80:4fbfa09ac26c 480 break;
orshefi 80:4fbfa09ac26c 481 case 8:
orshefi 80:4fbfa09ac26c 482 a = 33;
orshefi 80:4fbfa09ac26c 483 break;
orshefi 80:4fbfa09ac26c 484 case 9:
orshefi 80:4fbfa09ac26c 485 a = 37;
orshefi 80:4fbfa09ac26c 486 break;
orshefi 80:4fbfa09ac26c 487 }
orshefi 80:4fbfa09ac26c 488 switch(num2)
orshefi 80:4fbfa09ac26c 489 {
orshefi 80:4fbfa09ac26c 490 case 0:
orshefi 80:4fbfa09ac26c 491 b = 1;
orshefi 80:4fbfa09ac26c 492 break;
orshefi 80:4fbfa09ac26c 493 case 1:
orshefi 80:4fbfa09ac26c 494 b = 5;
orshefi 80:4fbfa09ac26c 495 break;
orshefi 80:4fbfa09ac26c 496 case 2:
orshefi 80:4fbfa09ac26c 497 b = 9;
orshefi 80:4fbfa09ac26c 498 break;
orshefi 80:4fbfa09ac26c 499 case 3:
orshefi 80:4fbfa09ac26c 500 b = 13;
orshefi 80:4fbfa09ac26c 501 break;
orshefi 80:4fbfa09ac26c 502 case 4:
orshefi 80:4fbfa09ac26c 503 b = 17;
orshefi 80:4fbfa09ac26c 504 break;
orshefi 80:4fbfa09ac26c 505 case 5:
orshefi 80:4fbfa09ac26c 506 b = 21;
orshefi 80:4fbfa09ac26c 507 break;
orshefi 80:4fbfa09ac26c 508 case 6:
orshefi 80:4fbfa09ac26c 509 b = 25;
orshefi 80:4fbfa09ac26c 510 break;
orshefi 80:4fbfa09ac26c 511 case 7:
orshefi 80:4fbfa09ac26c 512 b = 29;
orshefi 80:4fbfa09ac26c 513 break;
orshefi 80:4fbfa09ac26c 514 case 8:
orshefi 80:4fbfa09ac26c 515 b = 33;
orshefi 80:4fbfa09ac26c 516 break;
orshefi 80:4fbfa09ac26c 517 case 9:
orshefi 80:4fbfa09ac26c 518 b = 37;
orshefi 80:4fbfa09ac26c 519 break;
orshefi 80:4fbfa09ac26c 520 }
orshefi 80:4fbfa09ac26c 521 switch(num3)
orshefi 80:4fbfa09ac26c 522 {
orshefi 80:4fbfa09ac26c 523 case 0:
orshefi 80:4fbfa09ac26c 524 c = 1;
orshefi 80:4fbfa09ac26c 525 break;
orshefi 80:4fbfa09ac26c 526 case 1:
orshefi 80:4fbfa09ac26c 527 c = 5;
orshefi 80:4fbfa09ac26c 528 break;
orshefi 80:4fbfa09ac26c 529 case 2:
orshefi 80:4fbfa09ac26c 530 c = 9;
orshefi 80:4fbfa09ac26c 531 break;
orshefi 80:4fbfa09ac26c 532 case 3:
orshefi 80:4fbfa09ac26c 533 c = 13;
orshefi 80:4fbfa09ac26c 534 break;
orshefi 80:4fbfa09ac26c 535 case 4:
orshefi 80:4fbfa09ac26c 536 c = 17;
orshefi 80:4fbfa09ac26c 537 break;
orshefi 80:4fbfa09ac26c 538 case 5:
orshefi 80:4fbfa09ac26c 539 c = 21;
orshefi 80:4fbfa09ac26c 540 break;
orshefi 80:4fbfa09ac26c 541 case 6:
orshefi 80:4fbfa09ac26c 542 c = 25;
orshefi 80:4fbfa09ac26c 543 break;
orshefi 80:4fbfa09ac26c 544 case 7:
orshefi 80:4fbfa09ac26c 545 c = 29;
orshefi 80:4fbfa09ac26c 546 break;
orshefi 80:4fbfa09ac26c 547 case 8:
orshefi 80:4fbfa09ac26c 548 c = 33;
orshefi 80:4fbfa09ac26c 549 break;
orshefi 80:4fbfa09ac26c 550 case 9:
orshefi 80:4fbfa09ac26c 551 c = 37;
orshefi 80:4fbfa09ac26c 552 break;
orshefi 80:4fbfa09ac26c 553 }
orshefi 80:4fbfa09ac26c 554 unsigned char numodd[2] = {a,0};
orshefi 80:4fbfa09ac26c 555 unsigned char numeven[2] = {(a+1),0};
orshefi 80:4fbfa09ac26c 556 unsigned char numodd1[2] = {(a+2),0};
orshefi 80:4fbfa09ac26c 557 unsigned char numeven1[2] = {(a+3),0};
orshefi 80:4fbfa09ac26c 558 unsigned char numodd2[2] = {b,0};
orshefi 80:4fbfa09ac26c 559 unsigned char numeven2[2] = {(b+1),0};
orshefi 80:4fbfa09ac26c 560 unsigned char numodd3[2] = {(b+2),0};
orshefi 80:4fbfa09ac26c 561 unsigned char numeven3[2] = {(b+3),0};
orshefi 80:4fbfa09ac26c 562 unsigned char numodd4[2] = {c,0};
orshefi 80:4fbfa09ac26c 563 unsigned char numeven4[2] = {(c+1),0};
orshefi 80:4fbfa09ac26c 564 unsigned char numodd5[2] = {(c+2),0};
orshefi 80:4fbfa09ac26c 565 unsigned char numeven5[2] = {(c+3),0};
orshefi 80:4fbfa09ac26c 566 if(analog_read >=100)
orshefi 80:4fbfa09ac26c 567 {
orshefi 80:4fbfa09ac26c 568 Show_String_num(2,numodd,8,45);
orshefi 80:4fbfa09ac26c 569 Show_String_num(2,numeven,9,45);
orshefi 80:4fbfa09ac26c 570 Show_String_num(2,numodd1,10,45);
orshefi 80:4fbfa09ac26c 571 Show_String_num(2,numeven1,11,45);
orshefi 80:4fbfa09ac26c 572 Show_String_num(2,numodd2,8,71);
orshefi 80:4fbfa09ac26c 573 Show_String_num(2,numeven2,9,71);
orshefi 80:4fbfa09ac26c 574 Show_String_num(2,numodd3,10,71);
orshefi 80:4fbfa09ac26c 575 Show_String_num(2,numeven3,11,71);
orshefi 80:4fbfa09ac26c 576 Show_String_num(2,numodd4,8,97);
orshefi 80:4fbfa09ac26c 577 Show_String_num(2,numeven4,9,97);
orshefi 80:4fbfa09ac26c 578 Show_String_num(2,numodd5,10,97);
orshefi 80:4fbfa09ac26c 579 Show_String_num(2,numeven5,11,97);
orshefi 80:4fbfa09ac26c 580 }
orshefi 80:4fbfa09ac26c 581 else if(analog_read < 10)
orshefi 80:4fbfa09ac26c 582 {
orshefi 80:4fbfa09ac26c 583 Show_String_num(2,numodd4,8,71);
orshefi 80:4fbfa09ac26c 584 Show_String_num(2,numeven4,9,71);
orshefi 80:4fbfa09ac26c 585 Show_String_num(2,numodd5,10,71);
orshefi 80:4fbfa09ac26c 586 Show_String_num(2,numeven5,11,71);
orshefi 80:4fbfa09ac26c 587 }
orshefi 80:4fbfa09ac26c 588 else
orshefi 80:4fbfa09ac26c 589 {
orshefi 80:4fbfa09ac26c 590 Show_String_num(2,numodd2,8,58);
orshefi 80:4fbfa09ac26c 591 Show_String_num(2,numeven2,9,58);
orshefi 80:4fbfa09ac26c 592 Show_String_num(2,numodd3,10,58);
orshefi 80:4fbfa09ac26c 593 Show_String_num(2,numeven3,11,58);
orshefi 80:4fbfa09ac26c 594 Show_String_num(2,numodd4,8,84);
orshefi 80:4fbfa09ac26c 595 Show_String_num(2,numeven4,9,84);
orshefi 80:4fbfa09ac26c 596 Show_String_num(2,numodd5,10,84);
orshefi 80:4fbfa09ac26c 597 Show_String_num(2,numeven5,11,84);
orshefi 80:4fbfa09ac26c 598 }
orshefi 80:4fbfa09ac26c 599
orshefi 80:4fbfa09ac26c 600
orshefi 80:4fbfa09ac26c 601 }