Вс апр 19, 2020 06:29:53
Пн апр 20, 2020 04:58:35
//для проекта UA3REO-Sweep-Analyzer ссылки на оригинальный проект https://ua3reo.ru/izmerenie-parametrov-filtrov-i-konturov-na-arduino/
//GitHub https://github.com/XGudron/UA3REO-Sweep-Analyzer
Пт апр 24, 2020 08:52:18
Если есть желания в рамках данной темы выполнить адаптацию lgt8f328p можем продолжить.
Вт апр 28, 2020 01:38:47
#include <SPI.h>
#include "OneButton.h"
#include <avr/pgmspace.h>
#define ST7735_CS A3
#define ST7735_RST A4
#define ST7735_A0 6
#define ENC_CLK 2
#define ENC_DT A5
#define ENC_SW 3
#define W_CLK 7
#define FQ_UD 8
#define DATA 9
#define RESET A2
#define DAC 4
#define INP_VAL A0
#define INP_OUT A1
#define pulseHigh(pin) {digitalWrite(pin, HIGH); digitalWrite(pin, LOW); }
#define MULTIPLAY 0
#define MENU_MODE 1
#define SWIP_MODE 2
#define R6DCZ_MODE 3
#define KVN234_MODE 4
#define GEN_MODE 5
#define KVN_START_STOP 6
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x0400
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define VIOLET 0xEC1D
#define AQUA 0x07FF
#define YELLOW_GREEN 0x9E66
#define PURPLE 0x8010
String serial_readline = "";
const int bSize = 64;
char Buffer[bSize];
long freq = 3500000;
const uint16_t scr_width = 128;
const uint16_t scr_height = 128;
uint16_t OffSetX = 2;
uint16_t OffSetY = 1;
int enc_FreqStep = 1;
volatile unsigned long previousMillis;
const byte En_speed_1 = 50;
const byte En_speed_2 = 100;
const int Step_int_1 = 100;
const int Step_int_2 = 10;
long enc_StepMultip = 1;
int enc_ALast;
int enc_AVal;
float vin = 0;
float vout = 0;
float ratio = 0;
long lvin;
String freq_string_hz;
String freq_string_khz;
String freq_string_mhz;
byte fl_change = true;
byte menuLevel;
byte sw_Delay;
long fr_Start;
long fr_End;
long fr_Step;
typedef enum
{
scr_normal = 0,
scr_CW = 1,
scr_CCW = 2,
scr_180 = 3
} ScrOrientation_TypeDef;
typedef union
{
int i;
byte b[2];
} adc_type;
typedef union
{
long l;
byte b[4];
} frq_type;
OneButton button(ENC_SW, true);
void setup()
{
switchToExtQuartz();
pinMode(DAC, ANALOG);
pinMode(ST7735_RST, OUTPUT);
pinMode(ST7735_CS, OUTPUT);
pinMode(ST7735_A0, OUTPUT);
pinMode(ENC_CLK, INPUT_PULLUP);
pinMode(ENC_DT, INPUT_PULLUP);
pinMode(ENC_SW, INPUT_PULLUP);
pinMode(FQ_UD, OUTPUT);
pinMode(W_CLK, OUTPUT);
pinMode(DATA, OUTPUT);
pinMode(RESET, OUTPUT);
SPI.begin();
ST7735_init();
ST7735_Orientation(0);
ST7735_Clear(BLACK);
Serial.begin(115200);
Serial.setTimeout(50);
attachInterrupt(0, checkEncoder, CHANGE);
button.attachClick(switchMultiplier);
button.attachLongPressStop(switchToMenu);
sendFrequency(freq);
bitSet(fl_change, GEN_MODE);
menuLevel = GEN_MODE;
}
void switchToExtQuartz() {
bitSet(PMCR, PMCE);
bitSet(PMCR, OSCMEN);
asm("nop");
asm("nop");
asm("nop");
bitSet(PMCR, PMCE);
bitClear(PMCR, CLKFS);
bitSet(PMCR, CLKSS);
asm("nop");
asm("nop");
asm("nop");
}
void switchMultiplier()
{
if (enc_StepMultip == 1) enc_StepMultip = 1000;
else if (enc_StepMultip == 1000) enc_StepMultip = 1000000;
else enc_StepMultip = 1;
bitSet(fl_change, MULTIPLAY);
}
void checkEncoder() {
byte enc_DT;
long currentMillis;
enc_AVal = digitalRead(ENC_CLK);
enc_DT = digitalRead(ENC_DT);
enc_FreqStep = 1;
if (!enc_AVal && enc_ALast) {
currentMillis = millis();
if (currentMillis - previousMillis < En_speed_1) enc_FreqStep = Step_int_1;
else if (currentMillis - previousMillis < En_speed_2) enc_FreqStep = Step_int_2;
else enc_FreqStep = 1;
previousMillis = currentMillis;
if (enc_DT) {
if (bitRead(fl_change, MENU_MODE) == 1)
{
menuLevel --;
if (menuLevel <= SWIP_MODE) menuLevel = SWIP_MODE;
bitSet(fl_change, menuLevel);
}
else
{
freq = freq + enc_FreqStep * enc_StepMultip;
if (freq >= 40000000) freq = 40000000;
sendFrequency(freq);
}
}
else if (bitRead(fl_change, MENU_MODE) == 1)
{
menuLevel ++;
if (menuLevel >= GEN_MODE) menuLevel = GEN_MODE;
bitSet(fl_change, menuLevel);
}
else
{
freq = freq - enc_FreqStep * enc_StepMultip;
if (freq <= 0) freq = 0;
sendFrequency(freq);
}
}
enc_ALast = enc_AVal;
}
void tfr_byte(byte data)
{
for (int i = 0; i < 8; i++, data >>= 1) {
digitalWrite(DATA, data & 0x01);
pulseHigh(W_CLK);
}
}
void sendFrequency(double frequency) {
int32_t freq = frequency * 4294967295 / 125000000;
for (int b = 0; b < 4; b++, freq >>= 8) {
tfr_byte(freq & 0xFF);
}
tfr_byte(0x000);
pulseHigh(FQ_UD);
}
void readInVoltage()
{
vin = 0;
vout = 0;
lvin=0;
for (int i = 0; i < 4; i++)
{
if (menuLevel == KVN234_MODE) {
lvin = lvin + analogRead(INP_VAL);
} else {
vin = vin + ((float)analogRead(INP_VAL) / 4095 * 4.096);
vout = vout + ((float)analogRead(INP_OUT) / 4095 * 4.096);
}
}
vin = vin / 4;
vout = vout / 4;
ratio = vin / vout;
lvin = lvin / 4;
}
void printInfo()
{
readInVoltage();
String vol_str_in = "Inp: " + String(vin, 6) + "V";
String vol_str_out = "Gen: " + String(vout, 6) + "V";
String kp_str = "Rat: " + String(ratio, 6);
String dB_str = "dB : " + String(20 * log10(ratio), 6);
ST7735_PutStr7x11(0, 0, vol_str_out.c_str(), YELLOW, BLACK);
ST7735_PutStr7x11(0, 15, vol_str_in.c_str(), YELLOW, BLACK);
String fr_str = "000000000" + String(freq) + "Hz";
fr_str = "Frq: " + fr_str.substring(fr_str.length() - 10);
if (bitRead(fl_change, MULTIPLAY) == 1) {
ST7735_HLine(0, 127, 42, BLACK);
if (enc_StepMultip == 1000000) ST7735_HLine(40, 54, 42, AQUA);
else if (enc_StepMultip == 1000) ST7735_HLine(56, 78, 42, AQUA);
else if (enc_StepMultip == 1) ST7735_HLine(80, 102, 42, AQUA);
bitClear(fl_change, MULTIPLAY);
}
ST7735_PutStr7x11(0, 30, fr_str.c_str(), YELLOW, BLACK);
ST7735_PutStr7x11(0, 45, kp_str.c_str(), YELLOW, BLACK);
ST7735_PutStr7x11(0, 60, dB_str.c_str(), YELLOW, BLACK);
}
void switchToMenu()
{
ST7735_Clear(BLACK);
bitSet(fl_change, MENU_MODE);
bitSet(fl_change, menuLevel);
ST7735_Rect(0, 6, 127, 127, YELLOW);
ST7735_PutStr7x11(35, 0, "[ MODE ]", YELLOW, BLACK);
ST7735_PutStr7x11(45, 30, "SWEEP", YELLOW, BLACK);
ST7735_PutStr7x11(45, 50, "R6DCZ", YELLOW, BLACK);
ST7735_PutStr7x11(45, 70, "KVN234", YELLOW, BLACK);
ST7735_PutStr7x11(45, 90, "GEN", YELLOW, BLACK);
while (bitRead(fl_change, MENU_MODE) == 1)
{
if (digitalRead(ENC_SW) == LOW) bitClear(fl_change, MENU_MODE);
switch (menuLevel)
{
case SWIP_MODE:
if (bitRead(fl_change, SWIP_MODE) == 1)
{
ST7735_Rect(7, 27, 120, 43, CYAN);
ST7735_Rect(7, 47, 120, 63, BLACK);
ST7735_Rect(7, 67, 120, 83, BLACK);
ST7735_Rect(7, 87, 120, 103, BLACK);
bitClear(fl_change, SWIP_MODE);
}
break;
case R6DCZ_MODE:
if (bitRead(fl_change, R6DCZ_MODE) == 1)
{
ST7735_Rect(7, 47, 120, 63, CYAN);
ST7735_Rect(7, 87, 120, 103, BLACK);
ST7735_Rect(7, 67, 120, 83, BLACK);
ST7735_Rect(7, 27, 120, 43, BLACK);
bitClear(fl_change, R6DCZ_MODE);
}
break;
case KVN234_MODE:
if (bitRead(fl_change, KVN234_MODE) == 1)
{
ST7735_Rect(7, 67, 120, 83, CYAN);
ST7735_Rect(7, 47, 120, 63, BLACK);
ST7735_Rect(7, 87, 120, 103, BLACK);
ST7735_Rect(7, 27, 120, 43, BLACK);
bitClear(fl_change, KVN234_MODE);
}
break;
case GEN_MODE:
if (bitRead(fl_change, GEN_MODE) == 1)
{
ST7735_Rect(7, 87, 120, 103, CYAN);
ST7735_Rect(7, 47, 120, 63, BLACK);
ST7735_Rect(7, 67, 120, 83, BLACK);
ST7735_Rect(7, 27, 120, 43, BLACK);
bitClear(fl_change, GEN_MODE);
}
analogReference(INTERNAL4V096);
analogReadResolution(12);
break;
}
}
if ((menuLevel == GEN_MODE) or (menuLevel == SWIP_MODE))
{
ST7735_Clear(BLACK);
bitSet(fl_change, MULTIPLAY);
}
else if (menuLevel == R6DCZ_MODE) ST7735_Rect(7, 47, 120, 63, BLUE);
else if (menuLevel == KVN234_MODE) ST7735_Rect(7, 67, 120, 83, BLUE);
}
void loop()
{
long current_fr = fr_Start;
button.tick();
if (menuLevel == KVN234_MODE)
while (bitRead(fl_change, KVN_START_STOP) == 1)
{
sendFrequency(current_fr);
delay(sw_Delay);
readInVoltage();
sendData(current_fr);
current_fr = current_fr + fr_Step;
if (current_fr > fr_End) current_fr = fr_Start;
serialEvent();
}
if (menuLevel == R6DCZ_MODE)
{
while (Serial.available() > 0)
{
memset(Buffer, 0, bSize);
Serial.readBytes(Buffer, bSize);
serial_readline = String(Buffer);
if (serial_readline.startsWith("GET "))
{
fr_Start = (long)serial_readline.substring(4, 14).toFloat();
fr_End = (long)serial_readline.substring(15, 24).toFloat();
fr_Step = (long)serial_readline.substring(25).toFloat();
for (freq = fr_Start; freq <= fr_End; freq += fr_Step)
{
sendFrequency(freq);
readInVoltage();
String freq_str = "000000000" + String(freq) + " ";
String out_str = freq_str.substring(freq_str.length() - 10) + String(ratio, 6);
Serial.println(out_str);
}
}
Serial.flush();
}
}
if (menuLevel == GEN_MODE) printInfo();
}
void sendData(long fr)
{
byte crc;
adc_type adc ;
frq_type frq ;
adc.i = (int)lvin;
frq.l = (long)fr;
Serial.write(':'); Serial.write(9); Serial.write(6);
crc += ':'; crc += 9; crc += 6;
crc += frq.b[0]; crc += frq.b[1]; crc += frq.b[2]; crc += frq.b[3];
crc += adc.b[0]; crc += adc.b[1];
Serial.write(frq.b[0]); Serial.write(frq.b[1]); Serial.write(frq.b[2]); Serial.write(frq.b[3]);
Serial.write(adc.b[0]); Serial.write(adc.b[1]); Serial.write(crc);
}
void serialEvent()
{
if (menuLevel == KVN234_MODE)
{
while (Serial.available())
{
memset(Buffer, 0, bSize);
Serial.readBytes(Buffer, bSize);
if (Buffer[0] == ':')
{
byte len = Buffer[1];
if (len == 3)
{
byte inCommand = Buffer[2];
switch (inCommand)
{
case 0: {
bitSet(fl_change, KVN_START_STOP); //Start_Gkch
SendOK(0);
break;
}
case 1: {
bitClear(fl_change, KVN_START_STOP); //Stop_Gkch
SendOK(1);
break;
}
case 7: {
analogReference(INTERNAL1V024); //V1
analogReadResolution(12);
SendOK(7);
break;
}
case 8: {
analogReference(DEFAULT); //V5
analogReadResolution(10);
SendOK(8);
break;
}
case 9: {
SendOK(9); //A0
break;
}
case 10: {
SendOK(10); //A2
break;
}
case 16: {
SendOK(16); //A3
break;
}
case 17: {
SendOK(17); //A4
break;
}
}
}
else if (len == 4)
{
byte inCommand = Buffer[2];
switch (inCommand)
{
case 18: {
sw_Delay = Buffer[3]; //SET_PAUZ
SendOK(18);
break;
}
}
}
else if (len == 7)
{
byte inCommand = Buffer[2];
switch (inCommand)
{
case 2: {
fr_Start = pow(2, 32) * (byte)Buffer[6] + pow(2, 16) * (byte)Buffer[5] + pow(2, 8) * (byte)Buffer[4] + (byte)Buffer[3]; //Fr0
SendOK(2);
break;
}
case 3: {
fr_End = pow(2, 32) * (byte)Buffer[6] + pow(2, 16) * (byte)Buffer[5] + pow(2, 8) * (byte)Buffer[4] + (byte)Buffer[3]; //Fr1
SendOK(3);
break;
}
case 4: {
fr_Step = pow(2, 32) * (byte)Buffer[6] + pow(2, 16) * (byte)Buffer[5] + pow(2, 8) * (byte)Buffer[4] + (byte)Buffer[3]; //Step
SendOK(4);
break;
}
}
}
}
Serial.flush();
}
}
}
void SendOK(byte command)
{
char crc;
crc = ':'; crc += 3; crc += command;
Serial.write(':'); Serial.write(3); Serial.write(command); Serial.write(crc);
}
/*************************************************************************************************************
Драйвер lcg 1.44" 128X128 ST7735 VER 1.0. на красной плате
************************************************************************************************************/
char const Font7x11[] PROGMEM =
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // space 0x20 32
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x08, 0x08, // ! 0x21 33
0x12, 0x12, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // " 0x22 34
0x48, 0x48, 0x24, 0x7f, 0x24, 0x24, 0x12, 0x7f, 0x12, 0x09, 0x09, // # 0x23 35
0x08, 0x3e, 0x49, 0x09, 0x09, 0x3e, 0x48, 0x48, 0x49, 0x3e, 0x08, // $ 0x24 36
0x47, 0x25, 0x27, 0x10, 0x10, 0x08, 0x08, 0x04, 0x72, 0x52, 0x71, // % 0x25 37
0x06, 0x09, 0x09, 0x09, 0x26, 0x22, 0x25, 0x29, 0x11, 0x29, 0x46, // & 0x26 38
0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ' 0x27 39
0x08, 0x04, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x04, 0x04, 0x08, // ( 0x28 40
0x04, 0x08, 0x08, 0x10, 0x10, 0x10, 0x10, 0x10, 0x08, 0x08, 0x04, // ) 0x29 41
0x00, 0x08, 0x2a, 0x1c, 0x2a, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, // * 0x2A 42
0x00, 0x00, 0x00, 0x08, 0x08, 0x3e, 0x08, 0x08, 0x00, 0x00, 0x00, // + 0x2B 43
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x0c, 0x04, // , 0x2C 44
0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, // - 0x2D 45
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, // . 0x2E 46
0x10, 0x10, 0x10, 0x08, 0x08, 0x08, 0x04, 0x04, 0x04, 0x02, 0x02, // / 0x2F 47
0x1c, 0x22, 0x51, 0x51, 0x49, 0x49, 0x49, 0x45, 0x45, 0x22, 0x1c, // 0 0x30 48
0x08, 0x0c, 0x0a, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x3e, // 1 0x31 49
0x1e, 0x21, 0x40, 0x40, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x7f, // 2 0x32 50
0x1f, 0x20, 0x40, 0x40, 0x20, 0x1e, 0x20, 0x40, 0x40, 0x20, 0x1f, // 3 0x33 51
0x30, 0x28, 0x24, 0x22, 0x21, 0x7f, 0x20, 0x20, 0x20, 0x20, 0x20, // 4 0x34 52
0x7f, 0x01, 0x01, 0x01, 0x1f, 0x20, 0x40, 0x40, 0x40, 0x20, 0x1f, // 5 0x35 53
0x38, 0x04, 0x02, 0x01, 0x1d, 0x23, 0x41, 0x41, 0x41, 0x22, 0x1c, // 6 0x36 54
0x7f, 0x40, 0x20, 0x20, 0x10, 0x10, 0x08, 0x08, 0x04, 0x04, 0x02, // 7 0x37 55
0x1c, 0x22, 0x41, 0x41, 0x22, 0x1c, 0x22, 0x41, 0x41, 0x22, 0x1c, // 8 0x38 56
0x1c, 0x22, 0x41, 0x41, 0x41, 0x62, 0x5c, 0x40, 0x20, 0x10, 0x0e, // 9 0x39 57
0x00, 0x00, 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x0c, 0x0c, 0x00, 0x00, // : 0x3A 58
0x00, 0x00, 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x0c, 0x0c, 0x08, 0x04, // ; 0x3B 59
0x00, 0x40, 0x30, 0x0c, 0x02, 0x01, 0x02, 0x0c, 0x30, 0x40, 0x00, // < 0x3C 60
0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, // = 0x3D 61
0x00, 0x01, 0x06, 0x18, 0x20, 0x40, 0x20, 0x18, 0x06, 0x01, 0x00, // > 0x3E 62
0x3e, 0x41, 0x40, 0x40, 0x30, 0x08, 0x08, 0x08, 0x00, 0x08, 0x08, // ? 0x3F 63
0x1c, 0x22, 0x41, 0x49, 0x55, 0x55, 0x55, 0x39, 0x01, 0x02, 0x3c, // @ 0x40 64
0x08, 0x14, 0x14, 0x22, 0x22, 0x41, 0x41, 0x7f, 0x41, 0x41, 0x41, // A 0x41 65
0x1f, 0x21, 0x21, 0x21, 0x1f, 0x21, 0x41, 0x41, 0x41, 0x21, 0x1f, // B 0x42 66
0x3c, 0x42, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x42, 0x3c, // C 0x43 67
0x1f, 0x22, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x22, 0x1f, // D 0x44 68
0x7f, 0x01, 0x01, 0x01, 0x1f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x7f, // E 0x45 69
0x7f, 0x01, 0x01, 0x01, 0x3f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // F 0x46 70
0x3c, 0x42, 0x01, 0x01, 0x01, 0x79, 0x41, 0x41, 0x41, 0x42, 0x3c, // G 0x47 71
0x41, 0x41, 0x41, 0x41, 0x7f, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, // H 0x48 72
0x1c, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x1c, // I 0x49 73
0x1e, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x11, 0x0e, // J 0x4A 74
0x21, 0x11, 0x09, 0x05, 0x03, 0x03, 0x05, 0x09, 0x11, 0x21, 0x41, // K 0x4B 75
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x7f, // L 0x4C 76
0x41, 0x63, 0x55, 0x55, 0x49, 0x49, 0x41, 0x41, 0x41, 0x41, 0x41, // M 0x4D 77
0x41, 0x41, 0x41, 0x43, 0x43, 0x45, 0x49, 0x51, 0x51, 0x61, 0x41, // N 0x4E 78
0x1c, 0x22, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x22, 0x1c, // O 0x4F 79
0x1f, 0x21, 0x41, 0x41, 0x41, 0x21, 0x1f, 0x01, 0x01, 0x01, 0x01, // P 0x50 80
0x1c, 0x22, 0x41, 0x41, 0x41, 0x41, 0x41, 0x49, 0x51, 0x22, 0x5c, // Q 0x51 81
0x1f, 0x21, 0x41, 0x41, 0x41, 0x21, 0x1f, 0x09, 0x11, 0x21, 0x41, // R 0x52 82
0x1c, 0x22, 0x41, 0x01, 0x02, 0x1c, 0x20, 0x40, 0x41, 0x22, 0x1c, // S 0x53 83
0x7f, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, // T 0x54 84
0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x22, 0x1c, // U 0x55 85
0x41, 0x41, 0x22, 0x22, 0x22, 0x22, 0x14, 0x14, 0x14, 0x08, 0x08, // V 0x56 86
0x41, 0x41, 0x41, 0x41, 0x49, 0x49, 0x49, 0x55, 0x55, 0x63, 0x41, // W 0x57 87
0x41, 0x22, 0x22, 0x14, 0x08, 0x08, 0x08, 0x14, 0x22, 0x22, 0x41, // X 0x58 88
0x41, 0x41, 0x22, 0x14, 0x14, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, // Y 0x59 89
0x7f, 0x40, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, 0x01, 0x7f, // Z 0x5A 90
0x1c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x1c, // [ 0x5B 91
0x01, 0x02, 0x02, 0x04, 0x04, 0x04, 0x08, 0x08, 0x08, 0x10, 0x10, // \ 0x5C 92
0x0e, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0e, // ] 0x5D 93
0x08, 0x14, 0x22, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ^ 0x5E 94
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, // _ 0x5F 95
0x04, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ` 0x60 96
0x00, 0x00, 0x00, 0x3e, 0x41, 0x40, 0x7e, 0x41, 0x41, 0x61, 0x5e, // a 0x61 97
0x01, 0x01, 0x01, 0x1d, 0x23, 0x41, 0x41, 0x41, 0x41, 0x23, 0x1d, // b 0x62 98
0x00, 0x00, 0x00, 0x3c, 0x42, 0x01, 0x01, 0x01, 0x01, 0x42, 0x3c, // c 0x63 99
0x40, 0x40, 0x40, 0x5c, 0x62, 0x41, 0x41, 0x41, 0x41, 0x62, 0x5c, // d 0x64 100
0x00, 0x00, 0x00, 0x1c, 0x22, 0x41, 0x7f, 0x01, 0x01, 0x42, 0x3c, // e 0x65 101
0x1c, 0x04, 0x04, 0x0e, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, // f 0x66 102
0x00, 0x00, 0x00, 0x5e, 0x61, 0x41, 0x61, 0x5e, 0x40, 0x21, 0x1e, // g 0x67 103
0x01, 0x01, 0x01, 0x3d, 0x43, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, // h 0x68 104
0x08, 0x08, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, // i 0x69 105
0x00, 0x10, 0x00, 0x18, 0x10, 0x10, 0x10, 0x10, 0x10, 0x12, 0x0c, // j 0x6A 106
0x01, 0x01, 0x01, 0x21, 0x11, 0x09, 0x07, 0x09, 0x11, 0x21, 0x41, // k 0x6B 107
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x0c, // l 0x6C 108
0x00, 0x00, 0x00, 0x25, 0x5b, 0x49, 0x49, 0x49, 0x49, 0x49, 0x49, // m 0x6D 109
0x00, 0x00, 0x00, 0x1d, 0x23, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, // n 0x6E 110
0x00, 0x00, 0x00, 0x1c, 0x22, 0x41, 0x41, 0x41, 0x41, 0x22, 0x1c, // o 0x6F 111
0x00, 0x00, 0x00, 0x1f, 0x21, 0x41, 0x41, 0x21, 0x1f, 0x01, 0x01, // p 0x70 112
0x00, 0x00, 0x00, 0x2c, 0x32, 0x21, 0x21, 0x21, 0x32, 0x2c, 0x20, // q 0x71 113
0x00, 0x00, 0x00, 0x3d, 0x43, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // r 0x72 114
0x00, 0x00, 0x00, 0x3e, 0x41, 0x01, 0x0e, 0x30, 0x40, 0x41, 0x3e, // s 0x73 115
0x00, 0x04, 0x04, 0x3e, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x38, // t 0x74 116
0x00, 0x00, 0x00, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x31, 0x2e, // u 0x75 117
0x00, 0x00, 0x00, 0x41, 0x41, 0x22, 0x22, 0x14, 0x14, 0x08, 0x08, // v 0x76 118
0x00, 0x00, 0x00, 0x41, 0x41, 0x41, 0x49, 0x49, 0x49, 0x49, 0x36, // w 0x77 119
0x00, 0x00, 0x00, 0x41, 0x22, 0x14, 0x08, 0x08, 0x14, 0x22, 0x41, // x 0x78 120
0x00, 0x00, 0x00, 0x42, 0x42, 0x42, 0x24, 0x38, 0x10, 0x08, 0x06, // y 0x79 121
0x00, 0x00, 0x00, 0x7f, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, 0x7f, // z 0x7A 122
0x18, 0x08, 0x08, 0x08, 0x04, 0x06, 0x04, 0x08, 0x08, 0x08, 0x18, // { 0x7B 123
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, // | 0x7C 124
0x0c, 0x08, 0x08, 0x08, 0x10, 0x30, 0x10, 0x08, 0x08, 0x08, 0x0c, // } 0x7D 125
0x00, 0x00, 0x00, 0x00, 0x04, 0x0a, 0x51, 0x20, 0x00, 0x00, 0x00, // ~ 0x7E 126
0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f
}; // 0x7F 127
#define HWRST_SET digitalWrite(ST7735_RST,HIGH)
#define HWRST_RESET digitalWrite(ST7735_RST,LOW)
#define ST7735_COMMAND digitalWrite(ST7735_A0,LOW)
#define ST7735_DATA digitalWrite(ST7735_A0,HIGH)
#define ST7735_SELECT digitalWrite(ST7735_CS,LOW)
#define ST7735_UNSELECT digitalWrite(ST7735_CS,HIGH)
void ST7735_PutChar7x11(uint16_t X, uint16_t Y, uint8_t chr, uint16_t color, uint16_t bgcolor)
{
uint16_t i, j;
uint8_t buffer[11];
uint8_t CH = color >> 8;
uint8_t CL = (uint8_t)color;
uint8_t BCH = bgcolor >> 8;
uint8_t BCL = (uint8_t)bgcolor;
memcpy_P(buffer, &Font7x11[(chr - 32) * 11], 11);
ST7735_AddrSet(X, Y, X + 7, Y + 11);
ST7735_DATA;
for (i = 0; i < 11; i++)
{
for (j = 0; j < 7; j++)
{
if ((buffer[i] >> j) & 0x01)
{
ST7735_write(CH);
ST7735_write(CL);
}
else
{
ST7735_write(BCH);
ST7735_write(BCL);
}
}
ST7735_write(BCH);
ST7735_write(BCL);
}
for (i = 0; i < 8; i++)
{
ST7735_write(BCH);
ST7735_write(BCL);
}
}
void ST7735_PutStr7x11(uint8_t X, uint8_t Y, char *str, uint16_t color, uint16_t bgcolor)
{
while (*str)
{
ST7735_PutChar7x11(X, Y, *str++, color, bgcolor);
if (X < scr_width - 8) {
X += 8;
} else if (Y < scr_height - 12) {
X = 0;
Y += 12;
} else {
X = 0;
Y = 0;
}
};
}
void ST7735_Clear(uint16_t color)
{
uint16_t i;
uint8_t CH, CL;
CH = color >> 8;
CL = (uint8_t)color;
ST7735_AddrSet(0, 0, (scr_width - 1), (scr_height - 1));
ST7735_DATA;
for (i = 0; i < (scr_width * scr_height); i++) {
ST7735_write(CH);
ST7735_write(CL);
}
}
void ST7735_AddrSet(uint16_t XS, uint16_t YS, uint16_t XE, uint16_t YE)
{
XS = XS + OffSetX;
XE = XE + OffSetX;
YS = YS + OffSetY;
YE = YE + OffSetY;
ST7735_cmd(0x2a);
ST7735_DATA;
ST7735_write(XS >> 8);
ST7735_write(XS);
ST7735_write(XE >> 8);
ST7735_write(XE);
ST7735_cmd(0x2b);
ST7735_DATA;
ST7735_write(YS >> 8);
ST7735_write(YS);
ST7735_write(YE >> 8);
ST7735_write(YE);
ST7735_cmd(0x2c);
}
void ST7735_HWRST()
{
HWRST_RESET;
HWRST_SET;
}
void ST7735_data(uint8_t data)
{
ST7735_DATA;
ST7735_write(data);
}
void ST7735_SWRST()
{
ST7735_cmd(0x01);
ST7735_data(0x01);
}
void ST7735_write(uint8_t data)
{
ST7735_SELECT;
SPI.transfer(data);
ST7735_UNSELECT;
}
void ST7735_cmd(uint8_t cmd)
{
ST7735_COMMAND;
ST7735_write(cmd);
}
void ST7735_Pixel(uint16_t X, uint16_t Y, uint16_t color)
{
ST7735_AddrSet(X, Y, X, Y);
ST7735_DATA;
ST7735_write(color >> 8);
ST7735_write((uint8_t)color);
}
void ST7735_HLine(uint16_t X1, uint16_t X2, uint16_t Y, uint16_t color)
{
uint16_t i;
uint8_t CH = color >> 8;
uint8_t CL = (uint8_t)color;
ST7735_AddrSet(X1, Y, X2, Y);
ST7735_DATA;
for (i = 0; i <= (X2 - X1); i++)
{
ST7735_write(CH);
ST7735_write(CL);
}
}
void ST7735_VLine(uint16_t X, uint16_t Y1, uint16_t Y2, uint16_t color)
{
uint16_t i;
uint8_t CH = color >> 8;
uint8_t CL = (uint8_t)color;
ST7735_AddrSet(X, Y1, X, Y2);
ST7735_DATA;
for (i = 0; i <= (Y2 - Y1); i++)
{
ST7735_write(CH);
ST7735_write(CL);
}
}
void ST7735_Line(int16_t X1, int16_t Y1, int16_t X2, int16_t Y2, uint16_t color)
{
int16_t dX = X2 - X1;
int16_t dY = Y2 - Y1;
int16_t dXsym = (dX > 0) ? 1 : -1;
int16_t dYsym = (dY > 0) ? 1 : -1;
if (dX == 0)
{
if (Y2 > Y1) ST7735_VLine(X1, Y1, Y2, color); else ST7735_VLine(X1, Y2, Y1, color);
return;
}
if (dY == 0)
{
if (X2 > X1) ST7735_HLine(X1, X2, Y1, color); else ST7735_HLine(X2, X1, Y1, color);
return;
}
dX *= dXsym;
dY *= dYsym;
int16_t dX2 = dX << 1;
int16_t dY2 = dY << 1;
int16_t di;
if (dX >= dY)
{
di = dY2 - dX;
while (X1 != X2)
{
ST7735_Pixel(X1, Y1, color);
X1 += dXsym;
if (di < 0)
{
di += dY2;
}
else
{
di += dY2 - dX2;
Y1 += dYsym;
}
}
}
else
{
di = dX2 - dY;
while (Y1 != Y2)
{
ST7735_Pixel(X1, Y1, color);
Y1 += dYsym;
if (di < 0)
{
di += dX2;
}
else
{
di += dX2 - dY2;
X1 += dXsym;
}
}
}
ST7735_Pixel(X1, Y1, color);
}
void ST7735_Rect(uint16_t X1, uint16_t Y1, uint16_t X2, uint16_t Y2, uint16_t color)
{
ST7735_HLine(X1, X2, Y1, color);
ST7735_HLine(X1, X2, Y2, color);
ST7735_VLine(X1, Y1, Y2, color);
ST7735_VLine(X2, Y1, Y2, color);
}
void ST7735_FillRect(uint16_t X1, uint16_t Y1, uint16_t X2, uint16_t Y2, uint16_t color)
{
uint16_t i;
uint16_t FS = (X2 - X1 + 1) * (Y2 - Y1 + 1);
uint8_t CH = color >> 8;
uint8_t CL = (uint8_t)color;
ST7735_AddrSet(X1, Y1, X2, Y2);
ST7735_DATA;
for (i = 0; i < FS; i++)
{
ST7735_write(CH);
ST7735_write(CL);
}
}
void ST7735_init() {
ST7735_HWRST();
delay(15);
ST7735_SWRST();
delay(150);
ST7735_cmd(0x11); //SLPOUT
delay(255);
ST7735_cmd(0xb1); //FRMCTR1
ST7735_DATA;
ST7735_write(0x01);
ST7735_write(0x2c);
ST7735_write(0x2d);
ST7735_cmd(0xb2); //FRMCTR2
ST7735_DATA;
ST7735_write(0x01);
ST7735_write(0x2c);
ST7735_write(0x2d);
ST7735_cmd(0xb3); //FRMCTR3
ST7735_DATA;
ST7735_write(0x01);
ST7735_write(0x2c);
ST7735_write(0x2d);
ST7735_write(0x01);
ST7735_write(0x2c);
ST7735_write(0x2d);
ST7735_cmd(0xb4); //INVCTR
ST7735_data(0x07);
ST7735_cmd(0xc0); //PWCTR1
ST7735_DATA;
ST7735_write(0xa2);
ST7735_write(0x02);
ST7735_write(0x84);
ST7735_cmd(0xc1); //PWCTR2
ST7735_data(0xc5);
ST7735_cmd(0xC2); //PWCTR3
ST7735_DATA;
ST7735_write(0x0a);
ST7735_write(0x00);
ST7735_cmd(0xc3); //PWCTR4
ST7735_DATA;
ST7735_write(0x8a);
ST7735_write(0x2a);
ST7735_cmd(0xc4); //PWCTR5
ST7735_DATA;
ST7735_write(0x8a);
ST7735_write(0xee);
ST7735_cmd(0xc5); //VMCTR1
ST7735_data(0x0e);
ST7735_cmd(0x20); //INVOFF
ST7735_cmd(0x36); //MADCTL
ST7735_data(0x8);
ST7735_cmd(0x3a); //COLMOD
ST7735_data(0x05);
delay(10);
ST7735_cmd(0x2a); //CASET
ST7735_DATA;
ST7735_write(0x00);
ST7735_write(0x00);
ST7735_write(0x00);
ST7735_write(0x7f);
ST7735_cmd(0x2b); //RASET
ST7735_DATA;
ST7735_write(0x00);
ST7735_write(0x00);
ST7735_write(0x00);
ST7735_write(0x7f);
ST7735_cmd(0xe0); //GMCTRP1
ST7735_DATA;
ST7735_write(0x02);
ST7735_write(0x1c);
ST7735_write(0x07);
ST7735_write(0x12);
ST7735_write(0x37);
ST7735_write(0x32);
ST7735_write(0x29);
ST7735_write(0x2d);
ST7735_write(0x29);
ST7735_write(0x25);
ST7735_write(0x28);
ST7735_write(0x39);
ST7735_write(0x00);
ST7735_write(0x01);
ST7735_write(0x03);
ST7735_write(0x10);
ST7735_cmd(0xe1); //GMCTRN1
ST7735_DATA;
ST7735_write(0x03);
ST7735_write(0x1d);
ST7735_write(0x07);
ST7735_write(0x06);
ST7735_write(0x2e);
ST7735_write(0x2c);
ST7735_write(0x29);
ST7735_write(0x2d);
ST7735_write(0x2e);
ST7735_write(0x2e);
ST7735_write(0x37);
ST7735_write(0x3f);
ST7735_write(0x00);
ST7735_write(0x00);
ST7735_write(0x02);
ST7735_write(0x10);
ST7735_cmd(0x13); //NORON
delay(10);
ST7735_cmd(0x29); //DISPON
}
void ST7735_Orientation(ScrOrientation_TypeDef orientation)
{
ST7735_cmd(0x36); // Memory data access control:
switch (orientation)
{
case scr_CW:
OffSetX = 3;
OffSetY = 2;
ST7735_data(0xa8);
break;
case scr_CCW:
OffSetX = 1;
OffSetY = 2;
ST7735_data(0x68);
break;
case scr_180:
OffSetX = 2;
OffSetY = 3;
ST7735_data(0xc8);
break;
default:
OffSetX = 2;
OffSetY = 1;
ST7735_data(0x08);
break;
}
}
void ST7735_invertDisplay(boolean i) {
ST7735_cmd(i ? 0x21 : 0x20);
}
Вт апр 28, 2020 21:20:18
Ср июл 01, 2020 08:12:42
Чт июл 02, 2020 14:29:05
Вт июл 07, 2020 13:42:15
Вт июл 07, 2020 15:15:50
Ср июл 08, 2020 15:47:17
Пт июл 10, 2020 13:23:48
Ср дек 30, 2020 09:46:35
Ср дек 30, 2020 12:00:43
alex-551 писал(а): Подскажите, что надо сделать, что бы можно было пользоваться?
Ср дек 30, 2020 12:16:07
Ср дек 30, 2020 13:22:51
Ср дек 30, 2020 15:06:17
Ср дек 30, 2020 16:23:21
Ср дек 30, 2020 17:00:40
Ср дек 30, 2020 17:26:05
Чт дек 31, 2020 09:44:18