最近通过B站下载到“老刘爱鼓捣”的开源资料,是基于51单片机+OLED做的示波器,自己在复现过程中也付出了许多时间和经济成本,现将所学程序中的知识总结如下:
1、如果有需要资料,可自行B站搜索,如也要复现则首先建议直接买51开发板,加上外围器件,我自己买51芯片焊接时,容易出现无法烧写程序和OLED显示屏不亮的情况。
2、通过EEProm 储存 读取设定参数,并且将检查合法性作为一个函数,统一检查各参数。
bit Save_Options() { uint8 ops[15]; uint8 *p; check_Options(); p = ops; *p++ = Lsb >> 8; //дÈëLsb¸ß8λ uint16 *p++ = Lsb; //дÈëLsbµÍ8λ *p++ = PlotMode; //дÈë»æͼģʽ bit *p++ = ScaleH; //дÈëʱ¼äÇø¼ä char *p++ = ScaleV_Auto; //¶ÁÈ¡×Ô¶¯Á¿³Ì±êÖ¾ bit *p++ = RulerVMax >> 8; //дÈë×ÝÖáµçѹ¸ß8λ int16 *p++ = RulerVMax; //дÈë×ÝÖáµçѹµÍ8λ *p++ = RulerVMin >> 8; //дÈë×ÝÖáµçѹ¸ß8λ int16 *p++ = RulerVMin; //дÈë×ÝÖáµçѹµÍ8λ *p++ = TriLevel >> 8; //дÈë´¥·¢Öµ¸ß8λ int16 *p++ = TriLevel; //дÈë´¥·¢ÖµµÍ8λ *p++ = TriMode; //дÈë´¥·¢·½Ê½ int8 *p++ = TriSlope; //дÈë´¥·¢·½Ïò bit *p++ = WaveScroll; //дÈ벨Ðιö¶¯±êÖ¾ bit *p = OLED_Brightness; //дÈëOLEDÁÁ¶È uint8 // printf("Lsb=%hu\r\n",Lsb); // printf("DrawMode=%X\r\n",PlotMode); // printf("ScaleH=%bd\r\n",ScaleH); // printf("ScaleV_Auto=%X\r\n",ScaleV_Auto); // printf("RulerVMax=%hd\r\n",RulerVMax); // printf("RulerVMin=%hd\r\n",RulerVMin); // printf("TriLevel=%hd\r\n",TriLevel); // printf("TriMode=%bd\r\n",TriMode); // printf("TriSlope=%X\r\n",TriSlope); // printf("WaveScroll=%X\r\n",WaveScroll); // printf("OLED_Brightness=%bu\r\n",OLED_Brightness); // printf("\r\n"); return EEPROM_Save(ops, sizeof(ops) / sizeof(ops[0])); }
void Read_Options() { uint8 ops[15]; uint8 *p; p = ops; EEPROM_Read(ops, sizeof(ops) / sizeof(ops[0])); Lsb = *p++; //¶ÁÈ¡Lsb¸ß8λ uint16 Lsb <<= 8; //½«µÍ8λÒƵ½¸ß°Ëλ Lsb |= *p++; //¶ÁÈ¡LsbµÍ8λ PlotMode = *p++; //¶ÁÈ¡»æͼģʽ bit ScaleH = *p++; //¶Áȡʱ¼äÇø¼ä char ScaleV_Auto = *p++; //¶ÁÈ¡×Ô¶¯Á¿³Ì±êÖ¾ bit RulerVMax = *p++; //¶ÁÈ¡×ÝÖáµçѹ×î´óÖµ¸ß8λ int16 RulerVMax <<= 8; //½«µÍ8λÒƵ½¸ß°Ëλ RulerVMax |= *p++; //¶ÁÈ¡×ÝÖáµçѹ×î´óÖµµÍ8λ RulerVMin = *p++; //¶ÁÈ¡×ÝÖáµçѹ×îС¸ß8λ int16 RulerVMin <<= 8; //½«µÍ8λÒƵ½¸ß°Ëλ RulerVMin |= *p++; //¶ÁÈ¡×ÝÖáµçѹ×îСµÍ8λ TriLevel = *p++; //¶ÁÈ¡´¥·¢Öµ¸ß8λ int16 TriLevel <<= 8; //½«µÍ8λÒƵ½¸ß°Ëλ TriLevel |= *p++; //¶ÁÈ¡´¥·¢ÖµµÍ8λ TriMode = *p++; //¶ÁÈ¡´¥·¢·½Ê½ int8 TriSlope = *p++; //¶ÁÈ¡´¥·¢·½Ïò bit Wa