Porównaj commity
11 Commity
f04f5efd4d
...
12be30a333
Autor | SHA1 | Data |
---|---|---|
David Fainitski | 12be30a333 | |
David Fainitski | 78de94831c | |
David Fainitski | e85330a343 | |
David Fainitski | 1efb9c6e83 | |
David Fainitski | e8036b6b61 | |
David Fainitski | 1cf78a2c54 | |
David Fainitski | 3c4e5d648e | |
David Fainitski | 4065f680d8 | |
David Fainitski | f20860fb6d | |
David Fainitski | 21b179d5ac | |
David Fainitski | 8ba0e50516 |
|
@ -0,0 +1,116 @@
|
|||
<?xml version="1.0" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<title>HEX file checksum calculator - fischl.de</title>
|
||||
<link rel="stylesheet" type="text/css" href="../style.css"/>
|
||||
<meta name="keywords" content="HEX file, checksum, calculator"/>
|
||||
<meta name="description" content="HEX file checksum online calculator"/>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<style type="text/css">
|
||||
#start { background-color: #FFC; }
|
||||
#bytecount { background-color: #CFC; }
|
||||
#address { background-color: #CCF; }
|
||||
#type { background-color: #FCC; }
|
||||
#data { background-color: #CFF; }
|
||||
#checksum { background-color: #CCC; }
|
||||
#errors {
|
||||
color: red;
|
||||
}
|
||||
|
||||
|
||||
#hexline {
|
||||
width: 500px;
|
||||
}
|
||||
#calcresult {
|
||||
border: 2px solid #aaa;
|
||||
padding: 20px;
|
||||
display: none;
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
button {
|
||||
margin: 15px 0;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script type="text/javascript">
|
||||
function calculate() {
|
||||
var hexline = document.getElementById("hexline").value;
|
||||
var start = hexline.substring(0, 1);
|
||||
var bytecount = hexline.substring(1, 3);
|
||||
var bytecountDec = parseInt(bytecount, 16);
|
||||
var address = hexline.substring(3, 7);
|
||||
var addressDec = parseInt(address, 16);
|
||||
var type = hexline.substring(7, 9);
|
||||
var typeDec = parseInt(type, 16);
|
||||
var data = hexline.substring(9, 9 + 2 * bytecountDec);
|
||||
var checksum = hexline.substring(9 + 2 * bytecountDec, 9 + 2 * bytecountDec + 2);
|
||||
var checksumDec = parseInt(checksum, 16);
|
||||
|
||||
var typeString = "Unknown";
|
||||
switch (typeDec) {
|
||||
case 0x00: typeString = "Data"; break;
|
||||
case 0x01: typeString = "End Of File"; break;
|
||||
case 0x02: typeString = "Extended Segment Address"; break;
|
||||
case 0x03: typeString = "Start Segment Address"; break;
|
||||
case 0x04: typeString = "Extended Linear Address"; break;
|
||||
case 0x05: typeString = "Start Linear Address"; break;
|
||||
}
|
||||
|
||||
var i;
|
||||
var checksumVerify = 0;
|
||||
for (i = 0; i < bytecountDec + 4; i++) {
|
||||
var val = parseInt(hexline.substring(1 + i * 2, 3 + i * 2), 16);
|
||||
checksumVerify += val;
|
||||
}
|
||||
checksumVerify = checksumVerify % 256;
|
||||
if (checksumVerify > 0) checksumVerify = 256 - checksumVerify;
|
||||
|
||||
var errors = "";
|
||||
if (start != ':') errors += "Start byte must be ':'!<br/>";
|
||||
if (hexline.length < (bytecountDec * 2) + 9) errors += "Hex line too short! Some bytes are missing!<br/>";
|
||||
if (checksum.length < 2) errors += "Checksum too short!<br/>";
|
||||
if (checksumDec != checksumVerify) errors += "Checksum mismatch!<br/>";
|
||||
|
||||
document.getElementById("calcresult").innerHTML = "<span id='start'>" + start + "<\/span><span id='bytecount'>" + bytecount + "<\/span><span id='address'>" + address + "<\/span><span id='type'>" + type + "<\/span><span id='data'>" + data + "<\/span><span id='checksum'>" + checksum + "<\/span><br\/><br\/>" +
|
||||
"Address: " + address + "<sub>16<\/sub> = " + addressDec + "<sub>10<\/sub><br\/>" +
|
||||
"Byte count: " + bytecount + "<sub>16<\/sub> = " + bytecountDec + "<sub>10<\/sub><br\/>" +
|
||||
"Record type: " + type + "<sub>16<\/sub> = " + typeString + "<br\/>" +
|
||||
"Checksum: " + checksum + "<sub>16<\/sub><br\/><br\/>" +
|
||||
"Calculated checksum: " + ('0' + checksumVerify.toString(16).toUpperCase()).slice(-2) + "<sub>16<\/sub><br\/><br\/>" +
|
||||
"<span id='errors'>" + errors + "<\/span>";
|
||||
document.getElementById("calcresult").style.display = "block";
|
||||
}
|
||||
|
||||
window.onload = function () {
|
||||
document.getElementById("calculate").onclick = calculate;
|
||||
};
|
||||
</script>
|
||||
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div id="content">
|
||||
|
||||
|
||||
<h1>HEX file checksum online calculator</h1>
|
||||
<i>Firmware for microcontrollers are often stored in <a href="https://en.wikipedia.org/wiki/Intel_HEX">Intel HEX files</a>.
|
||||
For testing and debugging sometimes it is necessary to change some values directly in the HEX file.
|
||||
The Intel HEX file format is easy to read and to modify except the checksum.</i>
|
||||
|
||||
<h2>Analyse HEX file line</h2>
|
||||
Please enter one line of HEX file to analyze it, to calculate and verify the checksum. If you don't know the checksum, you can omit it.<br/>
|
||||
<br/>
|
||||
<form action="">
|
||||
<input type="text" id="hexline" value=":100130003F0156702B5E712B722B732146013421C7"/><br/>
|
||||
<button type="button" id="calculate">Analyse</button>
|
||||
</form>
|
||||
<div id="calcresult"></div>
|
||||
|
||||
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Plik binarny nie jest wyświetlany.
Plik binarny nie jest wyświetlany.
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0"?>
|
||||
<MCU_DEVICE_FLAGS>
|
||||
<DEVICE>
|
||||
<DEVICE_NAME>P16LF18877</DEVICE_NAME>
|
||||
<VALUE>
|
||||
<COUNT>5</COUNT>
|
||||
<VALUE0>
|
||||
<VAL>$008007:$2904</VAL>
|
||||
</VALUE0>
|
||||
<VALUE1>
|
||||
<VAL>$008008:$3E21</VAL>
|
||||
</VALUE1>
|
||||
<VALUE2>
|
||||
<VAL>$008009:$3F1F</VAL>
|
||||
</VALUE2>
|
||||
<VALUE3>
|
||||
<VAL>$00800A:$3003</VAL>
|
||||
</VALUE3>
|
||||
<VALUE4>
|
||||
<VAL>$00800B:$0003</VAL>
|
||||
</VALUE4>
|
||||
</VALUE>
|
||||
</DEVICE>
|
||||
</MCU_DEVICE_FLAGS>
|
|
@ -0,0 +1,24 @@
|
|||
0 1 mikroCPIC1618.exe -MSF -DBG -pP16LF18877 -RA -C -DL -O11111114 -fo32 -N"D:\Projects\ATU-10\Firmware_1.6\ATU-10.mcppi" -SP"C:\Program Files (x86)\mikroC PRO for PIC\Defs\" -SP"C:\Program Files (x86)\mikroC PRO for PIC\Uses\P16_Enh\" -SP"D:\Projects\ATU-10\Firmware_1.6\" -IP"C:\Program Files (x86)\mikroC PRO for PIC\Uses\P16_Enh\" "pic_init.c" "oled_control.c" "Soft_I2C.c" "main.c" "__Lib_Math.mcl" "__Lib_MathDouble.mcl" "__Lib_System.mcl" "__Lib_Delays.mcl" "__Lib_Conversions.mcl" "__Lib_Button.mcl" "__Lib_ADC_18xxx.mcl"
|
||||
hint: 0 1139 Available RAM: 4080 [bytes], Available ROM: 32768 [bytes]
|
||||
diagnostics: 0 122 Compilation Started P16LF18877.c
|
||||
diagnostics: 6696 123 Compiled Successfully P16LF18877.c
|
||||
diagnostics: 0 122 Compilation Started __Lib_Delays.c
|
||||
diagnostics: 123 123 Compiled Successfully __Lib_Delays.c
|
||||
diagnostics: 0 122 Compilation Started pic_init.c
|
||||
diagnostics: 62 123 Compiled Successfully pic_init.c
|
||||
diagnostics: 0 122 Compilation Started font_5x8.h
|
||||
diagnostics: 278 123 Compiled Successfully oled_control.c
|
||||
diagnostics: 0 122 Compilation Started soft_i2c.h
|
||||
diagnostics: 92 123 Compiled Successfully Soft_I2C.c
|
||||
diagnostics: 0 122 Compilation Started pic_init.h
|
||||
hint: 0 1004 interrupt handler (interupt at 0x0004) main.c
|
||||
hint: 603 1163 Variable 'swr_2' has been declared, but not used main.c
|
||||
hint: 603 1163 Variable 'pwr_2' has been declared, but not used main.c
|
||||
diagnostics: 953 123 Compiled Successfully main.c
|
||||
diagnostics: 0 127 All files Compiled in 187 ms
|
||||
hint: 0 1144 Used RAM (bytes): 406 (10%) Free RAM (bytes): 3674 (90%) Used RAM (bytes): 406 (10%) Free RAM (bytes): 3674 (90%)
|
||||
hint: 0 1144 Used ROM (program words): 9074 (28%) Free ROM (program words): 23694 (72%) Used ROM (program words): 9074 (28%) Free ROM (program words): 23694 (72%)
|
||||
diagnostics: 0 125 Project Linked Successfully ATU-10.mcppi
|
||||
diagnostics: 0 128 Linked in 78 ms
|
||||
diagnostics: 0 129 Project 'ATU-10.mcppi' completed: 406 ms
|
||||
diagnostics: 0 103 Finished successfully: 27 Dec 2022, 16:21:46 ATU-10.mcppi
|
|
@ -0,0 +1,5 @@
|
|||
[Position]
|
||||
Line=14
|
||||
Column=38
|
||||
[FoldedLines]
|
||||
Count=0
|
|
@ -0,0 +1,76 @@
|
|||
[DEVICE]
|
||||
Name=P16LF18877
|
||||
Clock=32000000
|
||||
[MEMORY_MODEL]
|
||||
Value=0
|
||||
[BUILD_TYPE]
|
||||
Value=0
|
||||
[ACTIVE_TAB]
|
||||
Value=main.c
|
||||
[USE_EEPROM]
|
||||
Value=0
|
||||
[USE_HEAP]
|
||||
Value=0
|
||||
[HEAP_SIZE]
|
||||
Value=0
|
||||
[EEPROM_DEFINITION]
|
||||
Value=
|
||||
[FILES]
|
||||
File0=pic_init.c
|
||||
File1=oled_control.c
|
||||
File2=Soft_I2C.c
|
||||
File3=main.c
|
||||
Count=4
|
||||
[BINARIES]
|
||||
Count=0
|
||||
[IMAGES]
|
||||
Count=0
|
||||
ActiveImageIndex=-1
|
||||
[OPENED_FILES]
|
||||
File0=pic_init.c
|
||||
File1=main.c
|
||||
File2=main.h
|
||||
File3=pic_init.h
|
||||
File4=oled_control.c
|
||||
File5=oled_control.h
|
||||
File6=Soft_I2C.c
|
||||
Count=7
|
||||
[EEPROM]
|
||||
Count=0
|
||||
[ACTIVE_COMMENTS_FILES]
|
||||
Count=0
|
||||
[OTHER_FILES]
|
||||
Count=0
|
||||
[SEARCH_PATH]
|
||||
Count=0
|
||||
[HEADER_PATH]
|
||||
Count=0
|
||||
[HEADERS]
|
||||
File0=pic_init.h
|
||||
File1=oled_control.h
|
||||
File2=Soft_I2C.h
|
||||
File3=font_5x8.h
|
||||
File4=main.h
|
||||
Count=5
|
||||
[PLDS]
|
||||
Count=0
|
||||
[Useses]
|
||||
File0=Button
|
||||
File1=Conversions
|
||||
File2=ADC
|
||||
Count=3
|
||||
[EXPANDED_NODES]
|
||||
0=ATU-10.mcppi
|
||||
1=Sources
|
||||
Count=2
|
||||
[LIB_EXPANDED_NODES]
|
||||
0=mikroE Libraries
|
||||
1=System Libraries
|
||||
Count=2
|
||||
[PROGRAMMER_TYPE]
|
||||
Value=mikroE mikroProg
|
||||
[CODEGRIP_OPTIONS]
|
||||
CODEGRIP_SPEED=0
|
||||
CODEGRIP_VERIFY_AFTER=0
|
||||
CODEGRIP_SWBP_ENABLED=0
|
||||
CODEGRIP_PROGRAMMING_TYPE=
|
Plik diff jest za duży
Load Diff
|
@ -0,0 +1,92 @@
|
|||
//
|
||||
#include "Soft_I2C.h"
|
||||
//
|
||||
#define Delay_I2C Delay_us(25)
|
||||
//
|
||||
// Software I2C connections
|
||||
#define Soft_I2C_Scl LATA3_bit
|
||||
#define Soft_I2C_Sda LATA2_bit
|
||||
#define Soft_I2C_Sda_in PORTA.B2
|
||||
#define Soft_I2C_Scl_in PORTA.B3
|
||||
//
|
||||
void Soft_I2C_Init(void) {
|
||||
Soft_I2C_Stop();
|
||||
return;
|
||||
}
|
||||
|
||||
void Soft_I2C_Start() {
|
||||
Soft_I2C_Scl = 1;
|
||||
Delay_I2C;
|
||||
Soft_I2C_Sda = 1;
|
||||
Delay_I2C;
|
||||
Soft_I2C_Sda = 0;
|
||||
Delay_I2C;
|
||||
Soft_I2C_Scl = 0;
|
||||
Delay_I2C;
|
||||
return;
|
||||
}
|
||||
|
||||
char Soft_I2C_Write(char d) {
|
||||
char i, ack;
|
||||
for(i=0; i<8; i++) {
|
||||
Soft_I2C_Sda = d.B7;
|
||||
Delay_I2C;
|
||||
Soft_I2C_Scl = 1;
|
||||
Delay_I2C;
|
||||
Soft_I2C_Scl = 0;
|
||||
d = d << 1;
|
||||
}
|
||||
//
|
||||
Soft_I2C_Sda = 1; //ACK
|
||||
Delay_I2C;
|
||||
Soft_I2C_Scl = 1;
|
||||
ack = Soft_I2C_Sda_in;
|
||||
Delay_I2C;
|
||||
Soft_I2C_Scl = 0;
|
||||
Delay_I2C;
|
||||
return ack;
|
||||
}
|
||||
|
||||
char Soft_I2C_Read(void){
|
||||
char i, d = 0;
|
||||
for(i=0; i<8; i++){
|
||||
d = d << 1;
|
||||
d = d + Soft_I2C_Sda_in;
|
||||
Soft_I2C_Scl = 1;
|
||||
Delay_I2C;
|
||||
Soft_I2C_Scl = 0;
|
||||
Delay_I2C;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
void Soft_I2C_ACK(void){
|
||||
Soft_I2C_Sda = 0;
|
||||
Delay_I2C;
|
||||
Soft_I2C_Scl = 1;
|
||||
Delay_I2C;
|
||||
Soft_I2C_Scl = 0;
|
||||
Soft_I2C_Sda = 1;
|
||||
Delay_I2C;
|
||||
return;
|
||||
}
|
||||
|
||||
void Soft_I2C_NACK(void){
|
||||
Soft_I2C_Sda = 1;
|
||||
Delay_I2C;
|
||||
Soft_I2C_Scl = 1;
|
||||
Delay_I2C;
|
||||
Soft_I2C_Scl = 0;
|
||||
Delay_I2C;
|
||||
return;
|
||||
}
|
||||
|
||||
void Soft_I2C_Stop() {
|
||||
Soft_I2C_Sda = 0;
|
||||
Delay_I2C;
|
||||
Soft_I2C_Scl = 1;
|
||||
Delay_I2C;
|
||||
Soft_I2C_Sda = 1;
|
||||
Delay_I2C;
|
||||
return;
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
[Position]
|
||||
Line=11
|
||||
Column=3
|
||||
[FoldedLines]
|
||||
Count=0
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
void Soft_I2C_Init(void);
|
||||
void Soft_I2C_Start(void);
|
||||
char Soft_I2C_Write(char);
|
||||
char Soft_I2C_Read(void);
|
||||
void Soft_I2C_ACK(void);
|
||||
void Soft_I2C_NACK(void);
|
||||
void Soft_I2C_Stop(void);
|
||||
//
|
|
@ -0,0 +1,5 @@
|
|||
[Position]
|
||||
Line=1
|
||||
Column=1
|
||||
[FoldedLines]
|
||||
Count=0
|
Plik binarny nie jest wyświetlany.
|
@ -0,0 +1,100 @@
|
|||
static const code char font_5x8[] = {
|
||||
//
|
||||
0x00, 0x00, 0x00, 0x00, 0x00,// (space)
|
||||
0x00, 0x00, 0x5F, 0x00, 0x00,// !
|
||||
0x00, 0x07, 0x00, 0x07, 0x00,// "
|
||||
0x14, 0x7F, 0x14, 0x7F, 0x14,// #
|
||||
0x24, 0x2A, 0x7F, 0x2A, 0x12,// $
|
||||
0x23, 0x13, 0x08, 0x64, 0x62,// %
|
||||
0x36, 0x49, 0x55, 0x22, 0x50,// &
|
||||
0x00, 0x05, 0x03, 0x00, 0x00,// '
|
||||
0x00, 0x1C, 0x22, 0x41, 0x00,// (
|
||||
0x00, 0x41, 0x22, 0x1C, 0x00,// )
|
||||
0x08, 0x2A, 0x1C, 0x2A, 0x08,// *
|
||||
0x08, 0x08, 0x3E, 0x08, 0x08,// +
|
||||
0x00, 0x50, 0x30, 0x00, 0x00,// ,
|
||||
0x08, 0x08, 0x08, 0x08, 0x08,// -
|
||||
0x00, 0x30, 0x30, 0x00, 0x00,// .
|
||||
0x20, 0x10, 0x08, 0x04, 0x02,// /
|
||||
0x3E, 0x51, 0x49, 0x45, 0x3E,// 0
|
||||
0x00, 0x42, 0x7F, 0x40, 0x00,// 1
|
||||
0x42, 0x61, 0x51, 0x49, 0x46,// 2
|
||||
0x21, 0x41, 0x45, 0x4B, 0x31,// 3
|
||||
0x18, 0x14, 0x12, 0x7F, 0x10,// 4
|
||||
0x27, 0x45, 0x45, 0x45, 0x39,// 5
|
||||
0x3C, 0x4A, 0x49, 0x49, 0x30,// 6
|
||||
0x01, 0x71, 0x09, 0x05, 0x03,// 7
|
||||
0x36, 0x49, 0x49, 0x49, 0x36,// 8
|
||||
0x06, 0x49, 0x49, 0x29, 0x1E,// 9
|
||||
0x00, 0x36, 0x36, 0x00, 0x00,// :
|
||||
0x00, 0x56, 0x36, 0x00, 0x00,// ;
|
||||
0x00, 0x08, 0x14, 0x22, 0x41,// <
|
||||
0x14, 0x14, 0x14, 0x14, 0x14,// =
|
||||
0x41, 0x22, 0x14, 0x08, 0x00,// >
|
||||
0x02, 0x01, 0x51, 0x09, 0x06,// ?
|
||||
0x32, 0x49, 0x79, 0x41, 0x3E,// @
|
||||
0x7E, 0x11, 0x11, 0x11, 0x7E,// A
|
||||
0x7F, 0x49, 0x49, 0x49, 0x36,// B
|
||||
0x3E, 0x41, 0x41, 0x41, 0x22,// C
|
||||
0x7F, 0x41, 0x41, 0x22, 0x1C,// D
|
||||
0x7F, 0x49, 0x49, 0x49, 0x41,// E
|
||||
0x7F, 0x09, 0x09, 0x01, 0x01,// F
|
||||
0x3E, 0x41, 0x41, 0x51, 0x32,// G
|
||||
0x7F, 0x08, 0x08, 0x08, 0x7F,// H
|
||||
0x00, 0x41, 0x7F, 0x41, 0x00,// I
|
||||
0x20, 0x40, 0x41, 0x3F, 0x01,// J
|
||||
0x7F, 0x08, 0x14, 0x22, 0x41,// K
|
||||
0x7F, 0x40, 0x40, 0x40, 0x40,// L
|
||||
0x7F, 0x02, 0x04, 0x02, 0x7F,// M
|
||||
0x7F, 0x04, 0x08, 0x10, 0x7F,// N
|
||||
0x3E, 0x41, 0x41, 0x41, 0x3E,// O
|
||||
0x7F, 0x09, 0x09, 0x09, 0x06,// P
|
||||
0x3E, 0x41, 0x51, 0x21, 0x5E,// Q
|
||||
0x7F, 0x09, 0x19, 0x29, 0x46,// R
|
||||
0x46, 0x49, 0x49, 0x49, 0x31,// S
|
||||
0x01, 0x01, 0x7F, 0x01, 0x01,// T
|
||||
0x3F, 0x40, 0x40, 0x40, 0x3F,// U
|
||||
0x1F, 0x20, 0x40, 0x20, 0x1F,// V
|
||||
0x7F, 0x20, 0x18, 0x20, 0x7F,// W
|
||||
0x63, 0x14, 0x08, 0x14, 0x63,// X
|
||||
0x03, 0x04, 0x78, 0x04, 0x03,// Y
|
||||
0x61, 0x51, 0x49, 0x45, 0x43,// Z
|
||||
0x00, 0x00, 0x7F, 0x41, 0x41,// [
|
||||
0x02, 0x04, 0x08, 0x10, 0x20,// "\"
|
||||
0x41, 0x41, 0x7F, 0x00, 0x00,// ]
|
||||
0x04, 0x02, 0x01, 0x02, 0x04,// ^
|
||||
0x40, 0x40, 0x40, 0x40, 0x40,// _
|
||||
0x00, 0x01, 0x02, 0x04, 0x00,// `
|
||||
0x20, 0x54, 0x54, 0x54, 0x78,// a
|
||||
0x7F, 0x48, 0x44, 0x44, 0x38,// b
|
||||
0x38, 0x44, 0x44, 0x44, 0x20,// c
|
||||
0x38, 0x44, 0x44, 0x48, 0x7F,// d
|
||||
0x38, 0x54, 0x54, 0x54, 0x18,// e
|
||||
0x08, 0x7E, 0x09, 0x01, 0x02,// f
|
||||
0x08, 0x14, 0x54, 0x54, 0x3C,// g
|
||||
0x7F, 0x08, 0x04, 0x04, 0x78,// h
|
||||
0x00, 0x44, 0x7D, 0x40, 0x00,// i
|
||||
0x20, 0x40, 0x44, 0x3D, 0x00,// j
|
||||
0x00, 0x7F, 0x10, 0x28, 0x44,// k
|
||||
0x00, 0x41, 0x7F, 0x40, 0x00,// l
|
||||
0x7C, 0x04, 0x18, 0x04, 0x78,// m
|
||||
0x7C, 0x08, 0x04, 0x04, 0x78,// n
|
||||
0x38, 0x44, 0x44, 0x44, 0x38,// o
|
||||
0x7C, 0x14, 0x14, 0x14, 0x08,// p
|
||||
0x08, 0x14, 0x14, 0x18, 0x7C,// q
|
||||
0x7C, 0x08, 0x04, 0x04, 0x08,// r
|
||||
0x48, 0x54, 0x54, 0x54, 0x20,// s
|
||||
0x04, 0x3F, 0x44, 0x40, 0x20,// t
|
||||
0x3C, 0x40, 0x40, 0x20, 0x7C,// u
|
||||
0x1C, 0x20, 0x40, 0x20, 0x1C,// v
|
||||
0x3C, 0x40, 0x30, 0x40, 0x3C,// w
|
||||
0x44, 0x28, 0x10, 0x28, 0x44,// x
|
||||
0x0C, 0x50, 0x50, 0x50, 0x3C,// y
|
||||
0x44, 0x64, 0x54, 0x4C, 0x44,// z
|
||||
0x00, 0x08, 0x36, 0x41, 0x00,// {
|
||||
0x00, 0x00, 0x7F, 0x00, 0x00,// |
|
||||
0x00, 0x41, 0x36, 0x08, 0x00,// }
|
||||
0x08, 0x08, 0x2A, 0x1C, 0x08,// ->
|
||||
0x08, 0x1C, 0x2A, 0x08, 0x08 // <-
|
||||
};
|
||||
//
|
|
@ -0,0 +1,5 @@
|
|||
[Position]
|
||||
Line=99
|
||||
Column=1
|
||||
[FoldedLines]
|
||||
Count=0
|
|
@ -0,0 +1,955 @@
|
|||
// David Fainitski, N7DDC
|
||||
// 2020
|
||||
|
||||
#include "pic_init.h"
|
||||
#include "main.h"
|
||||
#include "oled_control.h"
|
||||
#include "Soft_I2C.h"
|
||||
|
||||
|
||||
// global variables
|
||||
char txt[8], txt_2[8];
|
||||
unsigned long Tick = 0; // ms system tick
|
||||
int Voltage, Voltage_old = 0;
|
||||
char btn_1_cnt = 0, btn_2_cnt = 0;
|
||||
unsigned long volt_cnt = 0, watch_cnt = 0, btn_cnt = 0, off_cnt = 10, disp_cnt=10;
|
||||
int PWR, SWR, SWR_ind = 0, SWR_fixed_old = 100, PWR_fixed_old = 9999, rldl;
|
||||
char ind = 0, cap = 0, SW = 0;
|
||||
bit Overflow, B_short, B_long, B_xlong, gre, E_short, E_long;
|
||||
|
||||
// depending on Cells
|
||||
unsigned long Disp_time, Off_time;
|
||||
int Rel_Del, min_for_start, max_for_start, Auto_delta, Peak_cnt;
|
||||
bit Auto;
|
||||
float Cal_a, Cal_b;
|
||||
// Cells
|
||||
const char Cells[10] = {0x05, 0x30, 0x07, 0x10, 0x15, 0x13, 0x01, 0x04, 0x14, 0x60} absolute 0x7770;
|
||||
|
||||
#define FW_VER "1.6"
|
||||
|
||||
// interrupt processing
|
||||
void interupt() iv 0x0004 {
|
||||
//
|
||||
if(TMR0IF_bit) { // Timer0 every 1ms
|
||||
TMR0IF_bit = 0;
|
||||
Tick++;
|
||||
if(disp_cnt!=0) disp_cnt--;
|
||||
if(off_cnt!=0) off_cnt--;
|
||||
TMR0L = 0xC0; // 8_000 cycles to OF
|
||||
TMR0H = 0xE0;
|
||||
//
|
||||
if(Tick>=btn_cnt){ // every 10ms
|
||||
btn_cnt += 10;
|
||||
//
|
||||
if(GetButton | Start){
|
||||
disp_cnt = Disp_time;
|
||||
off_cnt = Off_time;
|
||||
}
|
||||
//
|
||||
if(GetButton){ //
|
||||
if(btn_1_cnt<250) btn_1_cnt++;
|
||||
if(btn_1_cnt==25) B_long = 1; // long pressing detected
|
||||
if(btn_1_cnt==250 & OLED_PWD) B_xlong = 1; // Xtra long pressing detected
|
||||
}
|
||||
else if(btn_1_cnt>2 & btn_1_cnt<25){
|
||||
B_short = 1; // short pressing detected
|
||||
btn_1_cnt = 0;
|
||||
}
|
||||
else
|
||||
btn_1_cnt = 0;
|
||||
// External interface
|
||||
if(Start){
|
||||
if(btn_2_cnt<25) btn_2_cnt++;
|
||||
if(btn_2_cnt==20 & Key_in) E_long = 1;
|
||||
}
|
||||
else if(btn_2_cnt>1 & btn_2_cnt<10){
|
||||
E_short = 1;
|
||||
btn_2_cnt = 0;
|
||||
}
|
||||
else
|
||||
btn_2_cnt = 0;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void main() {
|
||||
pic_init();
|
||||
cells_reading();
|
||||
Red = 1;
|
||||
Key_out = 1;
|
||||
gre = 1;
|
||||
oled_start();
|
||||
//if(Debug) check_reset_flags();
|
||||
ADC_Init();
|
||||
Overflow = 0;
|
||||
//
|
||||
disp_cnt = Disp_time;
|
||||
off_cnt = Off_time;
|
||||
//
|
||||
//Relay_set(0, 0, 0);
|
||||
//
|
||||
while(1) {
|
||||
if(Tick>=volt_cnt){ // every 3 second
|
||||
volt_cnt += 3000;
|
||||
Voltage_show();
|
||||
}
|
||||
//
|
||||
if(Tick>=watch_cnt){ // every 300 ms unless power off
|
||||
watch_cnt += 300;
|
||||
watch_swr();
|
||||
}
|
||||
//
|
||||
if(Disp_time!=0 && disp_cnt==0){ // Display off
|
||||
//Disp = 0;
|
||||
OLED_PWD = 0;
|
||||
}
|
||||
//
|
||||
if(Off_time!=0 && off_cnt==0){ // Go to power off
|
||||
power_off();
|
||||
}
|
||||
//
|
||||
if(B_short){
|
||||
if(OLED_PWD) Btn_short();
|
||||
else oled_start();
|
||||
}
|
||||
if(B_long){
|
||||
if(OLED_PWD) Btn_long();
|
||||
else oled_start();
|
||||
}
|
||||
if(B_xlong){
|
||||
if(OLED_PWD) Btn_xlong();
|
||||
else oled_start();
|
||||
}
|
||||
// External interface
|
||||
if(E_short){
|
||||
if(OLED_PWD==0) oled_start();
|
||||
Btn_short();
|
||||
}
|
||||
if(E_long){
|
||||
if(OLED_PWD==0) { Ext_long(); oled_start(); }
|
||||
else Btn_long();
|
||||
}
|
||||
|
||||
} // while(1)
|
||||
} // main
|
||||
//
|
||||
void oled_start(){
|
||||
OLED_PWD = 1;
|
||||
//Disp = 1;
|
||||
Delay_ms(200);
|
||||
Soft_I2C_Init();
|
||||
Delay_ms(10);
|
||||
oled_init();
|
||||
//
|
||||
if(gre){
|
||||
Greating();
|
||||
gre = 0;
|
||||
oled_clear();
|
||||
}
|
||||
oled_wr_str(0, 0, "PWR W", 9);
|
||||
oled_bat();
|
||||
oled_wr_str(2, 0, "SWR ", 9);
|
||||
oled_wr_str(0, 42, "=", 1);
|
||||
oled_wr_str(2, 42, "=", 1);
|
||||
Voltage_old = 9999;
|
||||
SWR_fixed_old = 100;
|
||||
PWR_fixed_old = 9999;
|
||||
SWR_ind = 0;
|
||||
draw_swr(SWR_ind);
|
||||
volt_cnt = Tick + 1;
|
||||
watch_cnt = Tick;
|
||||
B_short = 0; B_long = 0; B_xlong = 0, E_short = 0; E_long = 0;
|
||||
disp_cnt = Disp_time;
|
||||
off_cnt = Off_time;
|
||||
return;
|
||||
}
|
||||
//
|
||||
void watch_swr(void){
|
||||
int delta = Auto_delta - 100;
|
||||
int PWR_fixed, SWR_fixed, c;
|
||||
//
|
||||
Delay_ms(50);
|
||||
// peak detector
|
||||
PWR_fixed = 0;
|
||||
SWR_fixed = 0;
|
||||
for(c=0; c<Peak_cnt; c++){
|
||||
get_pwr();
|
||||
if(PWR>PWR_fixed) {PWR_fixed = PWR; SWR_fixed = SWR;}
|
||||
Delay_ms(1);
|
||||
}
|
||||
//
|
||||
if(PWR_fixed>0){ // Turn on the display
|
||||
if(OLED_PWD){
|
||||
disp_cnt = Disp_time;
|
||||
off_cnt = Off_time;
|
||||
}
|
||||
else oled_start();
|
||||
};
|
||||
//
|
||||
if(PWR_fixed!=PWR_fixed_old){
|
||||
if(Overflow)
|
||||
oled_wr_str(0, 42, ">", 1);
|
||||
else
|
||||
oled_wr_str(0, 42, "=", 1);
|
||||
PWR_fixed_old = PWR_fixed;
|
||||
draw_power(PWR_fixed);
|
||||
}
|
||||
//
|
||||
if(SWR_fixed>99 && SWR_fixed!=SWR_ind){
|
||||
SWR_ind = SWR_fixed;
|
||||
if(PWR_fixed<10){
|
||||
SWR_fixed = 0;
|
||||
//SWR_ind = 0; // Last meassured SWR on display ! not a bug
|
||||
draw_swr(SWR_ind);
|
||||
return;
|
||||
}
|
||||
else
|
||||
draw_swr(SWR_ind);
|
||||
}
|
||||
//
|
||||
if(Overflow){
|
||||
for(c=3; c!=0; c--){
|
||||
oled_wr_str(2, 6, "OVERLOAD ", 9);
|
||||
Delay_ms(500);
|
||||
oled_wr_str(2, 0, " ", 9);
|
||||
Delay_ms(500);
|
||||
}
|
||||
oled_wr_str(2, 0, "SWR ", 9);
|
||||
oled_wr_str(2, 42, "=", 1);
|
||||
draw_swr(SWR_fixed);
|
||||
Delay_ms(500);
|
||||
Overflow = 0;
|
||||
}
|
||||
//
|
||||
|
||||
else if(Auto && PWR_fixed>=min_for_start && PWR_fixed<max_for_start && SWR_fixed>120) {
|
||||
if( (SWR_fixed-SWR_fixed_old)>delta || (SWR_fixed_old-SWR_fixed)>delta || SWR_fixed>(999-delta) ) {
|
||||
Btn_long();
|
||||
return;
|
||||
}
|
||||
}
|
||||
//
|
||||
return;
|
||||
}
|
||||
//
|
||||
void draw_swr(unsigned int s){
|
||||
if(s==0)
|
||||
oled_wr_str(2, 60, "0.00", 4);
|
||||
else {
|
||||
IntToStr(s, txt_2);
|
||||
txt[0] = txt_2[3];
|
||||
txt[1] = '.';
|
||||
txt[2] = txt_2[4];
|
||||
txt[3] = txt_2[5];
|
||||
//
|
||||
oled_wr_str(2, 60, txt, 4);
|
||||
}
|
||||
return;
|
||||
}
|
||||
//
|
||||
void draw_power(unsigned int p){
|
||||
//
|
||||
if(p==0){
|
||||
oled_wr_str(0, 60, "0.0", 3);
|
||||
return;
|
||||
}
|
||||
else if(p<10){ // <1 W
|
||||
IntToStr(p, txt_2);
|
||||
txt[0] = '0';
|
||||
txt[1] = '.';
|
||||
txt[2] = txt_2[5];
|
||||
}
|
||||
else if(p<100){ // <10W
|
||||
IntToStr(p, txt_2);
|
||||
txt[0] = txt_2[4];
|
||||
txt[1] = '.';
|
||||
txt[2] = txt_2[5];
|
||||
}
|
||||
else{ // >10W
|
||||
p += 5;
|
||||
IntToStr(p, txt_2);
|
||||
txt[0] = ' ';
|
||||
txt[1] = txt_2[3];
|
||||
txt[2] = txt_2[4];
|
||||
}
|
||||
oled_wr_str(0, 60, txt, 3);
|
||||
return;
|
||||
}
|
||||
//
|
||||
void Voltage_show(){ // 4.2 - 3.4 4200 - 3400
|
||||
get_batt();
|
||||
if(Voltage != Voltage_old) {
|
||||
Voltage_old = Voltage;
|
||||
oled_voltage(Voltage);
|
||||
if(Voltage<=3800) rldl = Rel_Del + 1;
|
||||
else rldl = Rel_Del;
|
||||
}
|
||||
//
|
||||
if(Voltage>3700){
|
||||
Green = 0;
|
||||
Red = 1;
|
||||
Delay_ms(30);
|
||||
Green = 1;
|
||||
Red = 1;
|
||||
}
|
||||
else if(Voltage>3590){
|
||||
Green = 0;
|
||||
Red = 0;
|
||||
Delay_ms(30);
|
||||
Green = 1;
|
||||
Red = 1;
|
||||
}
|
||||
else { // <3.7V
|
||||
Red = 0;
|
||||
Green = 1;
|
||||
Delay_ms(30);
|
||||
Red = 1;
|
||||
Green = 1;
|
||||
}
|
||||
if(Voltage<3400){
|
||||
oled_clear();
|
||||
oled_wr_str(1, 0, " LOW BATT ", 11);
|
||||
Delay_ms(2000);
|
||||
OLED_PWD = 0;
|
||||
power_off();
|
||||
}
|
||||
return;
|
||||
}
|
||||
//
|
||||
void Btn_xlong(){
|
||||
oled_clear();
|
||||
oled_wr_str(1, 0, " POWER OFF ", 11);
|
||||
Delay_ms(2000);
|
||||
power_off();
|
||||
return;
|
||||
}
|
||||
//
|
||||
void Btn_long(){
|
||||
Green = 0;
|
||||
oled_wr_str(2, 0, "TUNE ", 9);
|
||||
Key_out = 0;
|
||||
tune();
|
||||
SWR_ind = SWR;
|
||||
SWR_fixed_old = SWR;
|
||||
oled_wr_str(2, 0, "SWR ", 4);
|
||||
oled_wr_str(2, 42, "=", 1);
|
||||
draw_swr(SWR_ind);
|
||||
Key_out = 1;
|
||||
Green = 1;
|
||||
B_long = 0;
|
||||
E_long = 0;
|
||||
btn_1_cnt = 0;
|
||||
volt_cnt = Tick;
|
||||
watch_cnt = Tick;
|
||||
return;
|
||||
}
|
||||
//
|
||||
void Ext_long(){
|
||||
Green = 0;
|
||||
OLED_PWD = 1;
|
||||
Key_out = 0; //
|
||||
get_swr(); //
|
||||
if(SWR>99){
|
||||
tune();
|
||||
}
|
||||
Key_out = 1; //
|
||||
SWR_ind = SWR;
|
||||
Green = 1;
|
||||
E_long = 0;
|
||||
return;
|
||||
}
|
||||
//
|
||||
void Btn_short(){
|
||||
Green = 0;
|
||||
atu_reset();
|
||||
oled_wr_str(2, 0, "RESET ", 9);
|
||||
Delay_ms(600);
|
||||
oled_wr_str(2, 0, "SWR ", 5);
|
||||
oled_wr_str(2, 42, "=", 1);
|
||||
oled_wr_str(2, 60, "0.00", 4);
|
||||
SWR_fixed_old = 0;
|
||||
Delay_ms(300);
|
||||
Green = 1;
|
||||
B_short = 0;
|
||||
E_short = 0;
|
||||
btn_1_cnt = 0;
|
||||
volt_cnt = Tick;
|
||||
watch_cnt = Tick;
|
||||
return;
|
||||
}
|
||||
//
|
||||
void Greating(){
|
||||
Green = 0;
|
||||
oled_clear();
|
||||
oled_wr_str_s(1, 0, " DESIGNED BY N7DDC", 18);
|
||||
oled_wr_str_s(3, 0, " FW VERSION ", 12);
|
||||
oled_wr_str_s(3, 12*7, FW_VER, 3);
|
||||
Delay_ms(3000);
|
||||
while(GetButton) asm NOP;
|
||||
Green = 1;
|
||||
return;
|
||||
}
|
||||
//
|
||||
void atu_reset(){
|
||||
ind = 0;
|
||||
cap = 1;
|
||||
SW = 0;
|
||||
Relay_set(ind, cap, SW);
|
||||
return;
|
||||
}
|
||||
//
|
||||
void Relay_set(char L, char C, char I){
|
||||
L_010 = ~L.B0;
|
||||
L_022 = ~L.B1;
|
||||
L_045 = ~L.B2;
|
||||
L_100 = ~L.B3;
|
||||
L_220 = ~L.B4;
|
||||
L_450 = ~L.B5;
|
||||
L_1000 = ~L.B6;
|
||||
//
|
||||
C_22 = ~C.B0;
|
||||
C_47 = ~C.B1;
|
||||
C_100 = ~C.B2;
|
||||
C_220 = ~C.B3;
|
||||
C_470 = ~C.B4;
|
||||
C_1000 = ~C.B5;
|
||||
C_2200 = ~C.B6;
|
||||
//
|
||||
C_sw = I;
|
||||
//
|
||||
Rel_to_gnd = 1;
|
||||
VDelay_ms(rldl);
|
||||
Rel_to_gnd = 0;
|
||||
Delay_us(10);
|
||||
Rel_to_plus_N = 0;
|
||||
VDelay_ms(rldl);
|
||||
Rel_to_plus_N = 1;
|
||||
VDelay_ms(rldl);
|
||||
//
|
||||
L_010 = 0;
|
||||
L_022 = 0;
|
||||
L_045 = 0;
|
||||
L_100 = 0;
|
||||
L_220 = 0;
|
||||
L_450 = 0;
|
||||
L_1000 = 0;
|
||||
//
|
||||
C_22 = 0;
|
||||
C_47 = 0;
|
||||
C_100 = 0;
|
||||
C_220 = 0;
|
||||
C_470 = 0;
|
||||
C_1000 = 0;
|
||||
C_2200 = 0;
|
||||
//
|
||||
C_sw = 0;
|
||||
Delay_ms(2);
|
||||
return;
|
||||
}
|
||||
//
|
||||
void power_off(void){
|
||||
char button_cnt;
|
||||
// Disable interrupts
|
||||
GIE_bit = 0;
|
||||
T0EN_bit = 0;
|
||||
TMR0IF_bit = 0;
|
||||
IOCIE_bit = 1;
|
||||
IOCBF5_bit = 0;
|
||||
IOCBN5_bit = 1;
|
||||
// Power saving
|
||||
OLED_PWD = 0;
|
||||
Red = 1;
|
||||
Green = 1;
|
||||
//
|
||||
button_cnt = 0;
|
||||
while(1){
|
||||
if(button_cnt==0){ Delay_ms(100); IOCBF5_bit = 0; asm sleep; }
|
||||
asm NOP;
|
||||
Delay_ms(100);
|
||||
if(GetButton) button_cnt++;
|
||||
else button_cnt = 0;
|
||||
if(button_cnt>15) break;
|
||||
}
|
||||
// Enable interrupts
|
||||
IOCIE_bit = 0;
|
||||
IOCBN5_bit = 0;
|
||||
IOCBF5_bit = 0;
|
||||
T0EN_bit = 1;
|
||||
GIE_bit = 1;
|
||||
// Return to work
|
||||
gre = 1;
|
||||
oled_start();
|
||||
while(GetButton){asm NOP;}
|
||||
btn_1_cnt = 0;
|
||||
B_short = 0;
|
||||
B_long = 0;
|
||||
B_xlong = 0;
|
||||
btn_cnt = Tick;
|
||||
return;
|
||||
}
|
||||
//
|
||||
void check_reset_flags(void){
|
||||
char i = 0;
|
||||
if(STKOVF_bit){oled_wr_str_s(0, 0, "Stack overflow", 14); i = 1;}
|
||||
if(STKUNF_bit){oled_wr_str_s(1, 0, "Stack underflow", 15); i = 1;}
|
||||
if(!nRWDT_bit){oled_wr_str_s(2, 0, "WDT overflow", 12); i = 1;}
|
||||
if(!nRMCLR_bit){oled_wr_str_s(3, 0, "MCLR reset ", 12); i = 1;}
|
||||
if(!nBOR_bit){oled_wr_str_s(4, 0, "BOR reset ", 12); i = 1;}
|
||||
if(i){
|
||||
Delay_ms(5000);
|
||||
oled_clear();
|
||||
}
|
||||
return;
|
||||
}
|
||||
//
|
||||
int get_reverse(void){
|
||||
unsigned int v;
|
||||
volatile unsigned long d;
|
||||
ADC_Init_Advanced(_ADC_INTERNAL_VREFL | _ADC_INTERNAL_FVRH1);
|
||||
Delay_us(100);
|
||||
v = ADC_Get_Sample(REV_input);
|
||||
if(v==1023){
|
||||
ADC_Init_Advanced(_ADC_INTERNAL_VREFL | _ADC_INTERNAL_FVRH2);
|
||||
Delay_us(100);
|
||||
v = ADC_Get_Sample(REV_input) * 2;
|
||||
}
|
||||
if(v==2046){
|
||||
ADC_Init_Advanced(_ADC_INTERNAL_VREFL | _ADC_INTERNAL_VREFH);
|
||||
Delay_us(100);
|
||||
v = ADC_Get_Sample(REV_input);
|
||||
if(v==1023) Overflow = 1;
|
||||
get_batt();
|
||||
d = (long)v * (long)Voltage;
|
||||
d = d / 1024;
|
||||
v = (int)d;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
//
|
||||
int get_forward(void){
|
||||
unsigned int v;
|
||||
volatile unsigned long d;
|
||||
ADC_Init_Advanced(_ADC_INTERNAL_VREFL | _ADC_INTERNAL_FVRH1);
|
||||
Delay_us(100);
|
||||
v = ADC_Get_Sample(FWD_input);
|
||||
if(v==1023){
|
||||
ADC_Init_Advanced(_ADC_INTERNAL_VREFL | _ADC_INTERNAL_FVRH2);
|
||||
Delay_us(100);
|
||||
v = ADC_Get_Sample(FWD_input) * 2;
|
||||
}
|
||||
if(v==2046){
|
||||
ADC_Init_Advanced(_ADC_INTERNAL_VREFL | _ADC_INTERNAL_VREFH);
|
||||
Delay_us(100);
|
||||
v = ADC_Get_Sample(FWD_input);
|
||||
if(v==1023) Overflow = 1;
|
||||
get_batt();
|
||||
d = (long)v * (long)Voltage;
|
||||
d = d / 1024;
|
||||
v = (int)d;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
//
|
||||
void get_pwr(){
|
||||
float F, R;
|
||||
volatile float gamma;
|
||||
//
|
||||
F = get_forward();
|
||||
R = get_reverse();
|
||||
F /= 1000; // to Volts
|
||||
R /= 1000; // to Volts
|
||||
F = Cal_a * F * F + Cal_b * F;
|
||||
R = Cal_a * R * R + Cal_b * R;
|
||||
PWR = (int)(F * 10 + 0.5); // 0 - 150 (0 - 15.0 Watts)
|
||||
//
|
||||
if(PWR>0){
|
||||
if(OLED_PWD){
|
||||
disp_cnt = Disp_time;
|
||||
off_cnt = Off_time;
|
||||
}
|
||||
else oled_start();
|
||||
}
|
||||
//
|
||||
if(PWR<10) SWR = 0; // < 1W
|
||||
else if(R >= F) SWR = 999;
|
||||
else {
|
||||
gamma = sqrt_n(R / F);
|
||||
if((1.0-gamma) == 0) gamma = 0.001;
|
||||
gamma = (1.0 + gamma) / (1.0 - gamma);
|
||||
if(gamma<1.0)
|
||||
gamma = 1.0;
|
||||
if(gamma>9.985) SWR = 999;
|
||||
else SWR = (int)(gamma * 100 + 0.5);
|
||||
}
|
||||
//
|
||||
return;
|
||||
}
|
||||
//
|
||||
float sqrt_n(float x){ // Thanks, Newton !
|
||||
char i;
|
||||
const char n = 8;
|
||||
float a[n];
|
||||
a[0] = x/2;
|
||||
for(i=1; i<(n); i++)
|
||||
a[i] = (a[i-1] + x/a[i-1]) / 2;
|
||||
//
|
||||
return a[n-1];
|
||||
}
|
||||
//
|
||||
void get_swr(){
|
||||
unsigned int pwr_cnt = 150, tuneoff_cnt = 300;
|
||||
unsigned int swr_1, swr_2, pwr_1, pwr_2, PWR_max = 0;
|
||||
char cnt;
|
||||
PWR = 0;
|
||||
SWR = 0;
|
||||
PWR_max = 0;
|
||||
//
|
||||
while(PWR<min_for_start || PWR>max_for_start){ // waiting for good power
|
||||
//
|
||||
if(B_short){
|
||||
Btn_short();
|
||||
SWR = 0;
|
||||
break;
|
||||
}
|
||||
if(B_xlong){
|
||||
//Btn_xlong();
|
||||
SWR = 0;
|
||||
break;
|
||||
}
|
||||
//
|
||||
swr_1 = 1000;
|
||||
for(cnt=5; cnt>0; cnt--){
|
||||
get_pwr();
|
||||
if(SWR<swr_1){
|
||||
swr_1 = SWR ;
|
||||
pwr_1 = PWR;
|
||||
Delay_us(500);
|
||||
}
|
||||
else{
|
||||
SWR = swr_1;
|
||||
PWR = pwr_1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
//
|
||||
if(PWR>min_for_start & PWR<max_for_start)
|
||||
break;
|
||||
//
|
||||
if(pwr_cnt>0){
|
||||
pwr_cnt --;
|
||||
if(PWR>PWR_max)
|
||||
PWR_max = PWR;
|
||||
}
|
||||
else {
|
||||
if(PWR_max!=PWR_fixed_old) draw_power(PWR_max);
|
||||
PWR_fixed_old = PWR_max;
|
||||
PWR_max = 0;
|
||||
pwr_cnt = 50;
|
||||
if(tuneoff_cnt>0) tuneoff_cnt--;
|
||||
else { SWR = 0; break; }
|
||||
}
|
||||
}
|
||||
// good power
|
||||
return;
|
||||
}
|
||||
//
|
||||
void get_batt(void){
|
||||
ADC_Init_Advanced(_ADC_INTERNAL_VREFL | _ADC_INTERNAL_FVRH1);
|
||||
Delay_us(100);
|
||||
Voltage = ADC_Get_Sample(Battery_input) * 11;
|
||||
return;
|
||||
}
|
||||
//
|
||||
void tune(void){
|
||||
int SWR_mem;
|
||||
char cap_mem, ind_mem;
|
||||
//
|
||||
get_swr();
|
||||
if(SWR<=120) return;
|
||||
subtune();
|
||||
get_swr();
|
||||
if(SWR<=120) return;
|
||||
SWR_mem = SWR;
|
||||
cap_mem = cap;
|
||||
ind_mem = ind;
|
||||
if(SW==1) SW = 0;
|
||||
else SW = 1;
|
||||
subtune();
|
||||
get_swr();
|
||||
if(SWR>SWR_mem){
|
||||
if(SW==1) SW = 0;
|
||||
else SW = 1;
|
||||
cap = cap_mem;
|
||||
ind = ind_mem;
|
||||
Relay_set(ind, cap, SW);
|
||||
get_swr();
|
||||
}
|
||||
if(SWR<=120) return;
|
||||
sharp_tune();
|
||||
get_swr();
|
||||
if(SWR==999)
|
||||
atu_reset();
|
||||
return;
|
||||
}
|
||||
//
|
||||
void subtune(void){
|
||||
cap = 0;
|
||||
ind = 0;
|
||||
Relay_set(ind, cap, SW);
|
||||
get_swr();
|
||||
if(SWR<=120) return;
|
||||
coarse_tune();
|
||||
get_swr();
|
||||
if(SWR<=120) return;
|
||||
sharp_tune();
|
||||
return;
|
||||
}
|
||||
//
|
||||
void coarse_tune(void){
|
||||
int SWR_mem1 = 10000, SWR_mem2 = 10000, SWR_mem3 = 10000;
|
||||
char ind_mem1, cap_mem1, ind_mem2, cap_mem2, ind_mem3, cap_mem3;
|
||||
coarse_cap();
|
||||
coarse_ind();
|
||||
get_swr();
|
||||
if(SWR<=120) return;
|
||||
SWR_mem1 = SWR;
|
||||
ind_mem1 = ind;
|
||||
cap_mem1 = cap;
|
||||
if(cap<=2 & ind<=2){
|
||||
cap = 0;
|
||||
ind = 0;
|
||||
Relay_set(ind, cap, SW);
|
||||
coarse_ind();
|
||||
coarse_cap();
|
||||
get_swr();
|
||||
if(SWR<=120) return;
|
||||
SWR_mem2 = SWR;
|
||||
ind_mem2 = ind;
|
||||
cap_mem2 = cap;
|
||||
}
|
||||
if(cap<=2 & ind<=2){
|
||||
cap = 0;
|
||||
ind = 0;
|
||||
Relay_set(ind, cap, SW);
|
||||
coarse_ind_cap();
|
||||
get_swr();
|
||||
if(SWR<=120) return;
|
||||
SWR_mem3 = SWR;
|
||||
ind_mem3 = ind;
|
||||
cap_mem3 = cap;
|
||||
}
|
||||
if(SWR_mem1<=SWR_mem2 & SWR_mem1<=SWR_mem3){
|
||||
cap = cap_mem1;
|
||||
ind = ind_mem1;
|
||||
}
|
||||
else if(SWR_mem2<=SWR_mem1 & SWR_mem2<=SWR_mem3){
|
||||
cap = cap_mem2;
|
||||
ind = ind_mem2;
|
||||
}
|
||||
else if(SWR_mem3<=SWR_mem1 & SWR_mem3<=SWR_mem2){
|
||||
cap = cap_mem3;
|
||||
ind = ind_mem3;
|
||||
}
|
||||
return;
|
||||
}
|
||||
//
|
||||
void coarse_ind_cap(void){
|
||||
int SWR_mem;
|
||||
char ind_mem;
|
||||
ind_mem = 0;
|
||||
get_swr();
|
||||
SWR_mem = SWR / 10;
|
||||
for(ind=1; ind<64; ind*=2){
|
||||
Relay_set(ind, ind, SW);
|
||||
get_swr();
|
||||
SWR = SWR/10;
|
||||
if(SWR<=SWR_mem){
|
||||
ind_mem = ind;
|
||||
SWR_mem = SWR;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
ind = ind_mem;
|
||||
cap = ind_mem;
|
||||
Relay_set(ind, cap, SW);
|
||||
return;
|
||||
}
|
||||
//
|
||||
void coarse_cap(void){
|
||||
int SWR_mem;
|
||||
char cap_mem;
|
||||
cap_mem = 0;
|
||||
get_swr();
|
||||
SWR_mem = SWR / 10;
|
||||
for(cap=1; cap<64; cap*=2){
|
||||
Relay_set(ind, cap, SW);
|
||||
get_swr();
|
||||
SWR = SWR/10;
|
||||
if(SWR<=SWR_mem){
|
||||
cap_mem = cap;
|
||||
SWR_mem = SWR;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
cap = cap_mem;
|
||||
Relay_set(ind, cap, SW);
|
||||
return;
|
||||
}
|
||||
//
|
||||
void coarse_ind(void){
|
||||
int SWR_mem;
|
||||
char ind_mem;
|
||||
ind_mem = 0;
|
||||
get_swr();
|
||||
SWR_mem = SWR / 10;
|
||||
for(ind=1; ind<64; ind*=2){
|
||||
Relay_set(ind, cap, SW);
|
||||
get_swr();
|
||||
SWR = SWR/10;
|
||||
if(SWR<=SWR_mem){
|
||||
ind_mem = ind;
|
||||
SWR_mem = SWR;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
ind = ind_mem;
|
||||
Relay_set(ind, cap, SW);
|
||||
return;
|
||||
}
|
||||
//
|
||||
void sharp_tune(void){
|
||||
if(cap>=ind){
|
||||
sharp_cap();
|
||||
sharp_ind();
|
||||
}
|
||||
else{
|
||||
sharp_ind();
|
||||
sharp_cap();
|
||||
}
|
||||
return;
|
||||
}
|
||||
//
|
||||
void sharp_cap(void){
|
||||
int SWR_mem;
|
||||
char step, cap_mem;
|
||||
cap_mem = cap;
|
||||
step = cap / 10;
|
||||
if(step==0) step = 1;
|
||||
get_swr();
|
||||
SWR_mem = SWR;
|
||||
cap += step;
|
||||
Relay_set(ind, cap, SW);
|
||||
get_swr();
|
||||
if(SWR<=SWR_mem){
|
||||
SWR_mem = SWR;
|
||||
cap_mem = cap;
|
||||
for(cap+=step; cap<=(127-step); cap+=step){
|
||||
Relay_set(ind, cap, SW);
|
||||
get_swr();
|
||||
if(SWR<=SWR_mem){
|
||||
cap_mem = cap;
|
||||
SWR_mem = SWR;
|
||||
step = cap / 10;
|
||||
if(step==0) step = 1;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
SWR_mem = SWR;
|
||||
for(cap-=step; cap>=step; cap-=step){
|
||||
Relay_set(ind, cap, SW);
|
||||
get_swr();
|
||||
if(SWR<=SWR_mem){
|
||||
cap_mem = cap;
|
||||
SWR_mem = SWR;
|
||||
step = cap / 10;
|
||||
if(step==0) step = 1;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
cap = cap_mem;
|
||||
Relay_set(ind, cap, SW);
|
||||
return;
|
||||
}
|
||||
//
|
||||
void sharp_ind(void){
|
||||
int SWR_mem;
|
||||
char step, ind_mem;
|
||||
ind_mem = ind;
|
||||
step = ind / 10;
|
||||
if(step==0) step = 1;
|
||||
get_swr();
|
||||
SWR_mem = SWR;
|
||||
ind += step;
|
||||
Relay_set(ind, cap, SW);
|
||||
get_swr();
|
||||
if(SWR<=SWR_mem){
|
||||
SWR_mem = SWR;
|
||||
ind_mem = ind;
|
||||
for(ind+=step; ind<=(127-step); ind+=step){
|
||||
Relay_set(ind, cap, SW);
|
||||
get_swr();
|
||||
if(SWR<=SWR_mem){
|
||||
ind_mem = ind;
|
||||
SWR_mem = SWR;
|
||||
step = ind / 10;
|
||||
if(step==0) step = 1;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
SWR_mem = SWR;
|
||||
for(ind-=step; ind>=step; ind-=step){
|
||||
Relay_set(ind, cap, SW);
|
||||
get_swr();
|
||||
if(SWR<=SWR_mem){
|
||||
ind_mem = ind;
|
||||
SWR_mem = SWR;
|
||||
step = ind / 10;
|
||||
if(step==0) step = 1;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
ind = ind_mem;
|
||||
Relay_set(ind, cap, SW);
|
||||
return;
|
||||
}
|
||||
//
|
||||
|
||||
void cells_reading(void){
|
||||
char i;
|
||||
char Cells_2[10];
|
||||
for(i=0; i<10; i++){
|
||||
Cells_2[i] = Cells[i];
|
||||
}
|
||||
//
|
||||
Disp_time = Bcd2Dec(Cells_2[0]) ;
|
||||
Disp_time *= 60000; // minutes to ms
|
||||
Off_time = Bcd2Dec(Cells_2[1]);
|
||||
Off_time *= 60000; // minutes to ms
|
||||
Rel_Del = Bcd2Dec(Cells_2[2]); // Delay in ms
|
||||
min_for_start = Bcd2Dec(Cells_2[3]); // Power with tens parts
|
||||
max_for_start = Bcd2Dec(Cells_2[4]) * 10; // power in Watts
|
||||
Auto_delta = Bcd2Dec(Cells_2[5]) * 10; // SWR with tens parts
|
||||
Auto = Bcd2Dec(Cells_2[6]);
|
||||
Cal_b = Bcd2Dec(Cells_2[7]) / 10.0;
|
||||
Cal_a = Bcd2Dec(Cells_2[8]) / 100.0 + 1.0;
|
||||
Peak_cnt = Bcd2Dec(Cells_2[9]) * 10 / 6;
|
||||
rldl = Rel_Del;
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
|
@ -0,0 +1,5 @@
|
|||
[Position]
|
||||
Line=638
|
||||
Column=117
|
||||
[FoldedLines]
|
||||
Count=0
|
|
@ -0,0 +1,48 @@
|
|||
|
||||
void pic_init(void);
|
||||
void Btn_long(void);
|
||||
void Btn_short(void);
|
||||
void Btn_xlong(void);
|
||||
void check_reset_flags(void);
|
||||
void Voltage_show(void);
|
||||
void Relay_set(char, char, char);
|
||||
int get_reverse(void);
|
||||
int get_forward(void);
|
||||
void get_pwr(void);
|
||||
void get_swr(void);
|
||||
void get_batt(void);
|
||||
void watch_swr(void);
|
||||
void coarse_cap(void);
|
||||
void tune(void);
|
||||
void subtune(void);
|
||||
void coarse_tune(void);
|
||||
void coarse_cap(void);
|
||||
void coarse_ind(void);
|
||||
void coarse_ind_cap(void);
|
||||
void sharp_tune(void);
|
||||
void sharp_cap(void);
|
||||
void sharp_ind(void);
|
||||
void atu_reset(void);
|
||||
void draw_swr(unsigned int);
|
||||
void draw_power(unsigned int);
|
||||
float sqrt_n(float);
|
||||
void oled_start(void);
|
||||
void power_off(void);
|
||||
void Greating(void);
|
||||
void Ext_long(void);
|
||||
void cells_reading(void);
|
||||
|
||||
|
||||
|
||||
#define ON 1
|
||||
#define OFF 0
|
||||
#define INT GIE_bit
|
||||
#define Battery_input 9
|
||||
#define FWD_input 8
|
||||
#define REV_input 10
|
||||
#define _AD_High ADFVR0_bit=0;ADFVR1_bit=1;
|
||||
#define _AD_Low ADFVR0_bit=1;ADFVR1_bit=0;
|
||||
#define Key_out LATD2_bit
|
||||
#define Key_in PORTD.B2
|
||||
#define Start_out LATD1_bit
|
||||
#define Start ~PORTD.B1
|
|
@ -0,0 +1,5 @@
|
|||
[Position]
|
||||
Line=33
|
||||
Column=1
|
||||
[FoldedLines]
|
||||
Count=0
|
Plik binarny nie jest wyświetlany.
|
@ -0,0 +1,279 @@
|
|||
#include "oled_control.h"
|
||||
#include "Soft_I2C.h"
|
||||
|
||||
void oled_disp_on() {
|
||||
send_command(0xAF); // display ON
|
||||
}
|
||||
|
||||
void oled_disp_off() {
|
||||
send_command(0xAE); // display OFF
|
||||
}
|
||||
|
||||
void oled_init (void) { // OLED init
|
||||
char cnt;
|
||||
for(cnt=0; cnt<10; cnt++){
|
||||
Soft_I2C_Start();
|
||||
if(Soft_I2C_Write(oled_addr)==0) break; // device addres
|
||||
else Soft_I2C_Stop();
|
||||
Delay_ms(300);
|
||||
}
|
||||
Soft_I2C_Write(0); // 0 - continious mode, command; 64 - Co, data
|
||||
Soft_I2C_Write (0xAE); // display OFF
|
||||
// initialisation
|
||||
Soft_I2C_Write (0xD5); // clock division
|
||||
Soft_I2C_Write (0x80); // ratio
|
||||
//
|
||||
Soft_I2C_Write (0xA8); // multiplexer
|
||||
Soft_I2C_Write (63); //
|
||||
//
|
||||
Soft_I2C_Write (0xD3); // offset
|
||||
Soft_I2C_Write (shift_line); // 32 no offset for x64 !
|
||||
//
|
||||
Soft_I2C_Write (0x40); // set line, line = 0
|
||||
//
|
||||
Soft_I2C_Write (0x8D); // charge pump
|
||||
Soft_I2C_Write (0x14); // 0x10 - external, 0x14 - internal
|
||||
//
|
||||
Soft_I2C_Write (0x81); // contrast
|
||||
Soft_I2C_Write (255); // 0-255
|
||||
//
|
||||
Soft_I2C_Write (0xD9); // pre-charge
|
||||
Soft_I2C_Write (0xF1); // 0x22 - external, 0xF1 - internal
|
||||
//
|
||||
Soft_I2C_Write (0x20); // memory addressing mode
|
||||
Soft_I2C_Write (0x02); // page addressing mode 02
|
||||
//
|
||||
Soft_I2C_Write (0x21); // set column range
|
||||
Soft_I2C_Write (0); // column start
|
||||
Soft_I2C_Write (127); // column stop
|
||||
//
|
||||
Soft_I2C_Write (0x2E); // stop scrolling
|
||||
//
|
||||
if(inversion) {
|
||||
Soft_I2C_Write (0xA0); // segment re-map, A0 - normal, A1 - remapped
|
||||
Soft_I2C_Write (0xC0); // scan direction, C0 - normal, C8 - remapped
|
||||
}
|
||||
else {
|
||||
Soft_I2C_Write (0xA1); // segment re-map, A0 - normal, A1 - remapped
|
||||
Soft_I2C_Write (0xC8); // scan direction, C0 - normal, C8 - remapped
|
||||
}
|
||||
//
|
||||
Soft_I2C_Write (0xDA); // COM pins configure
|
||||
Soft_I2C_Write (0x02); // 02 for 32 12 for x64
|
||||
//
|
||||
Soft_I2C_Write (0xDB); // V-COM detect
|
||||
Soft_I2C_Write (0x40); //
|
||||
//
|
||||
Soft_I2C_Write (0xA4); // display entire ON
|
||||
//
|
||||
Soft_I2C_Write (0xA6); // 0xA6 - normal, 0xA7 - inverse
|
||||
//
|
||||
Soft_I2C_Stop ();
|
||||
//
|
||||
oled_clear();
|
||||
send_command (0xAF); // display ON
|
||||
return;
|
||||
}
|
||||
|
||||
void oled_clear(void){
|
||||
char i, r;
|
||||
// ********clear OLED***********
|
||||
Soft_I2C_Start();
|
||||
Soft_I2C_Write(oled_addr); // device addres
|
||||
Soft_I2C_Write(64); // 0 - continious mode, command; 64 - Co, data
|
||||
//
|
||||
for (r = 0; r <=7; r++) {
|
||||
set_addressing (r, 0); // clear all 8 pages
|
||||
for (i = 0; i < 128; i++, Soft_I2C_Write(0x00)); // clear one page pixels
|
||||
}
|
||||
Soft_I2C_Stop ();
|
||||
//
|
||||
return;
|
||||
}
|
||||
|
||||
void send_command (char oled_command) {
|
||||
Soft_I2C_Start();
|
||||
Soft_I2C_Write(oled_addr); // device addres
|
||||
Soft_I2C_Write(128); // 128 - command, 192 - data
|
||||
Soft_I2C_Write(oled_command);
|
||||
Soft_I2C_Stop();
|
||||
return;
|
||||
}
|
||||
|
||||
void set_addressing (char pagenum, char c_start) {
|
||||
char a, b, c;
|
||||
c = c_start + oled_shift;
|
||||
Soft_I2C_Start();
|
||||
Soft_I2C_Write(oled_addr); // device addres
|
||||
Soft_I2C_Write(0); // 0 - continious mode, command; 64 - Co, data
|
||||
Soft_I2C_Write(0xB0 + pagenum); // set page number
|
||||
//
|
||||
if (c <= 15) { a = c; b = 0; }
|
||||
else { b = c / 16; a = c - b * 16; }
|
||||
Soft_I2C_Write (a); // set lower nibble of start address
|
||||
Soft_I2C_Write (0x10 + b); // set higher nibble of start address
|
||||
//
|
||||
Soft_I2C_Start();
|
||||
Soft_I2C_Write(oled_addr); // device addres
|
||||
Soft_I2C_Write(64); // 0 - continious mode, command; 64 - Co, data
|
||||
return;
|
||||
}
|
||||
|
||||
void oled_wr_str_s(char page, char col, char str[], char len) { // 128*64 OLED
|
||||
char i, h, g;
|
||||
set_addressing (page, col);
|
||||
//
|
||||
for (i = 0; i < len; i++) { // write string
|
||||
g = str[i] - 32; // table shift
|
||||
for (h = 0; h < 5; h++) { // write letter
|
||||
Soft_I2C_Write(font_5x8[g*5+h]);
|
||||
}
|
||||
Soft_I2C_Write (0);
|
||||
}
|
||||
Soft_I2C_Stop ();
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
void oled_wr_str (char page, char col, char str[], char leng ) { //
|
||||
char i, h, g, w1, w2;
|
||||
Soft_I2C_Start();
|
||||
Soft_I2C_Write(oled_addr); // device addres
|
||||
Soft_I2C_Write(64); // 0 - continious mode, command; 64 - Co, data
|
||||
//
|
||||
set_addressing (page, col);
|
||||
//
|
||||
for (i = 0; i < leng; i++) { // write string
|
||||
if (str[i] == 0) g = 0; else g = str[i] - 32; // NULL detection
|
||||
for (h = 0; h <= 4; h++) { // write letter
|
||||
w1 = font_5x8[g*5+h];
|
||||
if(page != 2) {
|
||||
w2.B7 = w1.B3;
|
||||
w2.B6 = w1.B3;
|
||||
w2.B5 = w1.B2;
|
||||
w2.B4 = w1.B2;
|
||||
w2.B3 = w1.B1;
|
||||
w2.B2 = w1.B1;
|
||||
w2.B1 = w1.B0;
|
||||
w2.B0 = w1.B0; }
|
||||
else {
|
||||
w2.B7 = w1.B2;
|
||||
w2.B6 = w1.B2;
|
||||
w2.B5 = w1.B1;
|
||||
w2.B4 = w1.B1;
|
||||
w2.B3 = w1.B0;
|
||||
w2.B2 = w1.B0;
|
||||
w2.B1 = 0;
|
||||
w2.B0 = 0;
|
||||
}
|
||||
Soft_I2C_Write(w2);
|
||||
Soft_I2C_Write(w2);
|
||||
}
|
||||
Soft_I2C_Write (0);
|
||||
Soft_I2C_Write (0);
|
||||
}
|
||||
set_addressing (page+1, col);
|
||||
//
|
||||
for (i = 0; i < leng; i++) { // write string
|
||||
if (str[i] == 0) g = 0; else g = str[i] - 32; // NULL detection
|
||||
for (h = 0; h <= 4; h++) { // write letter
|
||||
w1 = font_5x8[g*5+h];
|
||||
if(page != 2) {
|
||||
w2.B7 = w1.B7;
|
||||
w2.B6 = w1.B7;
|
||||
w2.B5 = w1.B6;
|
||||
w2.B4 = w1.B6;
|
||||
w2.B3 = w1.B5;
|
||||
w2.B2 = w1.B5;
|
||||
w2.B1 = w1.B4;
|
||||
w2.B0 = w1.B4; }
|
||||
else {
|
||||
w2.B7 = w1.B6;
|
||||
w2.B6 = w1.B6;
|
||||
w2.B5 = w1.B5;
|
||||
w2.B4 = w1.B5;
|
||||
w2.B3 = w1.B4;
|
||||
w2.B2 = w1.B4;
|
||||
w2.B1 = w1.B3;
|
||||
w2.B0 = w1.B3;
|
||||
}
|
||||
Soft_I2C_Write(w2);
|
||||
Soft_I2C_Write(w2);
|
||||
}
|
||||
Soft_I2C_Write (0);
|
||||
Soft_I2C_Write (0);
|
||||
}
|
||||
Soft_I2C_Stop ();
|
||||
}
|
||||
|
||||
//
|
||||
void oled_bat () {
|
||||
char i, g;
|
||||
Soft_I2C_Start();
|
||||
Soft_I2C_Write(oled_addr); // device addres
|
||||
Soft_I2C_Write(64); // 0 - continious mode, command; 64 - Co, data
|
||||
//
|
||||
|
||||
for(g=0; g<=3; g++) { // batt drawing
|
||||
set_addressing (g, 115);
|
||||
for(i=0; i<=10; i++) { Soft_I2C_Write(batt[g*11+i]); }
|
||||
}
|
||||
Soft_I2C_Stop ();
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
void oled_voltage(int Voltage) {
|
||||
char i, v, u0, u1, u2, u3, m;
|
||||
Soft_I2C_Start();
|
||||
Soft_I2C_Write(oled_addr); // device addres
|
||||
Soft_I2C_Write(64); // 0 - continious mode, command; 64 - Co, data
|
||||
//
|
||||
Voltage /= 10;
|
||||
if(Voltage < 300) Voltage = 300;
|
||||
else if(Voltage > 420) Voltage = 420;
|
||||
Voltage = Voltage - 300; // 0 - 120
|
||||
Voltage = Voltage * 32;
|
||||
v = Voltage / 120;
|
||||
|
||||
|
||||
if(v >= 25) { u0 = v - 24; u1 = 8; u2 = 8; u3 = 8; }
|
||||
else if(v >= 17) { u0 = 0; u1 = v - 16; u2 = 8; u3 = 8; }
|
||||
else if(v >= 9 ) { u0 = 0; u1 = 0; u2 = v - 8; u3 = 8; }
|
||||
else { u0 = 0; u1 = 0; u2 = 0; u3 = v ; }
|
||||
|
||||
m = 128;
|
||||
m = 255 - (m >> (u0-1)) +1;
|
||||
m = m | 0b00000011;
|
||||
set_addressing (0, 119);
|
||||
Soft_I2C_Write(m);
|
||||
Soft_I2C_Write(m);
|
||||
Soft_I2C_Write(m);
|
||||
m = m | 0b00011111;
|
||||
set_addressing (0, 117);
|
||||
Soft_I2C_Write(m);
|
||||
Soft_I2C_Write(m);
|
||||
set_addressing (0, 122);
|
||||
Soft_I2C_Write(m);
|
||||
Soft_I2C_Write(m);
|
||||
|
||||
m = 128;
|
||||
m = 255 - (m >> (u1-1)) + 1;
|
||||
set_addressing (1, 117);
|
||||
for(i=0; i<=6; i++) Soft_I2C_Write(m);
|
||||
|
||||
m = 128;
|
||||
m = 255 - (m >> (u2-1)) + 1;
|
||||
set_addressing (2, 117);
|
||||
for(i=0; i<=6; i++) Soft_I2C_Write(m);
|
||||
|
||||
m = 128;
|
||||
m = 255 - (m >> (u3-1)) +1;
|
||||
m = m | 0b11000000;
|
||||
set_addressing (3, 117);
|
||||
for(i=0; i<=6; i++) Soft_I2C_Write(m);
|
||||
//
|
||||
Soft_I2C_Stop ();
|
||||
return;
|
||||
}
|
||||
//
|
|
@ -0,0 +1,5 @@
|
|||
[Position]
|
||||
Line=18
|
||||
Column=17
|
||||
[FoldedLines]
|
||||
Count=0
|
|
@ -0,0 +1,69 @@
|
|||
#include "font_5x8.h"
|
||||
|
||||
static oled_addr = 0x78;
|
||||
static char shift_line = 64; // shift the image down
|
||||
static char oled_shift = 2; // shift the image left
|
||||
static char inversion = 1;
|
||||
//
|
||||
void oled_init (void);
|
||||
void oled_clear(void);
|
||||
void send_command (char);
|
||||
void set_addressing (char, char);
|
||||
void oled_wr_str_s(char, char, char*, char);
|
||||
void oled_wr_str(char, char, char*, char);
|
||||
void oled_bat (void);
|
||||
void oled_voltage (int);
|
||||
void oled_clear (void);
|
||||
|
||||
//
|
||||
static const char batt[] = {
|
||||
0B11111000,
|
||||
0B11111000,
|
||||
|
||||
0B00011111,
|
||||
0B00011111,
|
||||
0B00000011,
|
||||
0B00000011,
|
||||
0B00000011,
|
||||
0B00011111,
|
||||
0B00011111,
|
||||
|
||||
0B11111000,
|
||||
0B11111000,
|
||||
//
|
||||
0B11111111,
|
||||
0B11111111,
|
||||
0B00000000,
|
||||
0B00000000,
|
||||
0B00000000,
|
||||
0B00000000,
|
||||
0B00000000,
|
||||
0B00000000,
|
||||
0B00000000,
|
||||
0B11111111,
|
||||
0B11111111,
|
||||
//
|
||||
0B11111111,
|
||||
0B11111111,
|
||||
0B00000000,
|
||||
0B00000000,
|
||||
0B00000000,
|
||||
0B00000000,
|
||||
0B00000000,
|
||||
0B00000000,
|
||||
0B00000000,
|
||||
0B11111111,
|
||||
0B11111111,
|
||||
//
|
||||
0B11111111,
|
||||
0B11111111,
|
||||
0B11000000,
|
||||
0B11000000,
|
||||
0B11000000,
|
||||
0B11000000,
|
||||
0B11000000,
|
||||
0B11000000,
|
||||
0B11000000,
|
||||
0B11111111,
|
||||
0B11111111
|
||||
};
|
|
@ -0,0 +1,5 @@
|
|||
[Position]
|
||||
Line=1
|
||||
Column=1
|
||||
[FoldedLines]
|
||||
Count=0
|
Plik binarny nie jest wyświetlany.
|
@ -0,0 +1,62 @@
|
|||
// pic_init unit for Micro C PRO
|
||||
// 2020
|
||||
|
||||
void pic_init (void) {
|
||||
// ports initialisation
|
||||
ANSELA = 0; // all as digital
|
||||
ANSELB = 0; // all as digital
|
||||
ANSB0_bit = 1; // analog input
|
||||
ANSB1_bit = 1; // analog input
|
||||
ANSB2_bit = 1; // analog input
|
||||
ANSELC = 0; // all as digital
|
||||
ANSELE = 0; // all as digital
|
||||
ANSELD = 0; // all as digital
|
||||
|
||||
C1ON_bit = 0; // Disable comparators
|
||||
C2ON_bit = 0;
|
||||
|
||||
PORTA = 0;
|
||||
PORTB = 0;
|
||||
PORTC = 0;
|
||||
PORTD = 0;
|
||||
PORTE = 0;
|
||||
LATA = 0b00000000;
|
||||
LATB = 0b00000000;
|
||||
LATC = 0b00010000;
|
||||
LATD = 0b00000110;
|
||||
LATE = 0b00000000;
|
||||
TRISA = 0b00000000;
|
||||
TRISB = 0b00100111;
|
||||
TRISC = 0b00000000;
|
||||
TRISD = 0b00000000;
|
||||
TRISE = 0b00000000;
|
||||
|
||||
// open drains
|
||||
ODCA2_bit = 1;
|
||||
ODCA3_bit = 1;
|
||||
ODCD1_bit = 1;
|
||||
ODCD2_bit = 1;
|
||||
|
||||
// Timer0 settings
|
||||
T0CS0_bit = 0; // Fosc/4
|
||||
T0CS1_bit = 1;
|
||||
T0CS2_bit = 0;
|
||||
T016BIT_bit = 1;
|
||||
TMR0L = 0xC0; // 8_000 cycles to OF
|
||||
TMR0H = 0xE0;
|
||||
TMR0IF_bit = 0;
|
||||
T0EN_bit = 1;
|
||||
TMR0IE_bit = 1;
|
||||
|
||||
// Modules disable
|
||||
PMD0 = 0b00011110; //
|
||||
PMD1 = 0b11111110;
|
||||
PMD2 = 0b01000111;
|
||||
PMD3 = 0b01111111;
|
||||
PMD4 = 0b1110111;
|
||||
PMD5 = 0b11011111;
|
||||
//interrupt setting
|
||||
GIE_bit = 1;
|
||||
Delay_ms (100);
|
||||
return;
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
[Position]
|
||||
Line=1
|
||||
Column=33
|
||||
[FoldedLines]
|
||||
Count=0
|
|
@ -0,0 +1,24 @@
|
|||
// Connections
|
||||
//
|
||||
#define GetButton ~ PORTB.B5
|
||||
//
|
||||
sbit Red at LATB4_bit;
|
||||
sbit Green at LATB3_bit;
|
||||
sbit OLED_PWD at LATA4_bit;
|
||||
sbit C_sw at LATE0_bit;
|
||||
sbit L_010 at LATD7_bit;
|
||||
sbit L_022 at LATD6_bit;
|
||||
sbit L_045 at LATD5_bit;
|
||||
sbit L_100 at LATD4_bit;
|
||||
sbit L_220 at LATC7_bit;
|
||||
sbit L_450 at LATC6_bit;
|
||||
sbit L_1000 at LATC5_bit;
|
||||
sbit C_22 at LATA5_bit;
|
||||
sbit C_47 at LATE1_bit;
|
||||
sbit C_100 at LATA7_bit;
|
||||
sbit C_220 at LATA6_bit;
|
||||
sbit C_470 at LATC0_bit;
|
||||
sbit C_1000 at LATC1_bit;
|
||||
sbit C_2200 at LATC2_bit;
|
||||
sbit Rel_to_gnd at LATD3_bit;
|
||||
sbit Rel_to_plus_N at LATC4_bit;
|
|
@ -0,0 +1,5 @@
|
|||
[Position]
|
||||
Line=1
|
||||
Column=1
|
||||
[FoldedLines]
|
||||
Count=0
|
Plik binarny nie jest wyświetlany.
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 160 KiB |
26
README.md
26
README.md
|
@ -3,8 +3,30 @@
|
|||
### Official conversation group - https://groups.io/g/ATU100
|
||||
### Schematic and assembly instruction by VK3PE - http://carnut.info/ATU_N7DDC/ATU-10/ATU-10_by-vk3pe_build_info/ATU-10_vk3pe_V1.2_ALL_INFO_290921.pdf
|
||||
|
||||
###### AON FW is always on
|
||||
no automatic power off. Use button to power off after using to avoid discharging the battery.
|
||||
###### New in FW version 1.6
|
||||
1 - New better meassurement formula for Power and SWR calculation, compensation and calibration.
|
||||
2 - Setting by Cells control implementation. There are 10 cells you can find opening a FW .hex file in Notepad++ program as Intel HEX file.
|
||||
At the end by address EEE0 and EEF0 you can see them and change values. After changing any value you must to correct a checksumm for each
|
||||
changed string. Copy the needed string into Checsumm.html and get correct checksumm. It should be green color before you can save changed .hex FW file.
|
||||
|
||||
[![](https://github.com/Dfinitski/ATU-10-10W-QRP-antenna-tuner/blob/main/Photos/Cells.jpg)](https://github.com/Dfinitski/ATU-10-10W-QRP-antenna-tuner/blob/main/Photos/Cells.jpg)
|
||||
|
||||
Cells description:
|
||||
1) Time to display off in minutes, 5 mins by default, 0 to always on display
|
||||
2) time to power off in minutes, 30 mins by default, 0 to always power on
|
||||
3) relay's delay time, voltage applied to coiles in ms, 7 ms by default
|
||||
4) min power to start tuning in ten's parts of Watt, 10 by default (1.0 W). This value can not be 0
|
||||
5) max power to start tuning in watts, 15 by default
|
||||
6) Delta SWR to auto start tuning in ten's parts SWR, 13 by default (SWR = 1.3)
|
||||
7) Auto mode 1 for activate or 0 to off. 1 by default
|
||||
8) Calibration coefficient for 1W power, 4 by default for BAT41 diodes
|
||||
9) calibration coefficient for 10W power, 14 by default for BAT41 diodes
|
||||
10) Peak detector time for Power meassurement in tens ms, 60 (600ms)
|
||||
|
||||
If you are using 1N5711 diodes in the RF detector, you can calibrate the power meassurement.
|
||||
Apply known 1W of power on 7MHz and change cell 8 for correct value.
|
||||
Apply known 10W of power on 7MHw and change cell 9 for correct value.
|
||||
Repeat it couple times to reach a good result.
|
||||
|
||||
###### New in FW version 1.5
|
||||
1 - Tuning algorithm improvement
|
||||
|
|
Ładowanie…
Reference in New Issue