Skip to content

Commit

Permalink
lcdtest and extended ubutton tested
Browse files Browse the repository at this point in the history
  • Loading branch information
phdlee committed Apr 18, 2018
1 parent f600c18 commit 5611e1c
Show file tree
Hide file tree
Showing 7 changed files with 396 additions and 1,306 deletions.
19 changes: 11 additions & 8 deletions ubitx_20/ubitx.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,22 @@
//==============================================================================
// Compile Option
//==============================================================================
#define ENABLE_FACTORYALIGN
#define ENABLE_ADCMONITOR //Starting with Version 1.07, you can read ADC values directly from uBITX Manager. So this function is not necessary.

//Depending on the type of LCD mounted on the uBITX, uncomment one of the options below.
//You must select only one.
//#define UBITX_DISPLAY_LCD1602P //LCD mounted on unmodified uBITX
//#define UBITX_DISPLAY_LCD1602I //I2C type 16 x 02 LCD
#define UBITX_DISPLAY_LCD1602I_CUST //I2C type 16 x 02 Custom Tiny Library
//#define UBITX_DISPLAY_LCD2004P //24 x 04 LCD
//#define UBITX_DISPLAY_LCD2004I //I2C type 24 x 04 LCD
#define UBITX_DISPLAY_LCD2004P //24 x 04 LCD (Parallel)
//#define UBITX_DISPLAY_LCD2004I //I2C type 24 x 04 LCD

#define I2C_DISPLAY_ADDRESS 0x3F //0x27 //DEFAULT, if Set I2C Address by uBITX Manager, read from EEProm

//#define EXTEND_KEY_GROUP1 //MODE, BAND(-), BAND(+), STEP
//#define EXTEND_KEY_GROUP2 //Numeric (0~9), Point(.), Enter //Not supported in Version 1.0x

#define ENABLE_FACTORYALIGN
#define ENABLE_ADCMONITOR //Starting with Version 1.07, you can read ADC values directly from uBITX Manager. So this function is not necessary.

//#define EXTEND_KEY_GROUP1 //MODE, BAND(-), BAND(+), STEP
//#define EXTEND_KEY_GROUP2 //Numeric (0~9), Point(.), Enter //Not supported in Version 1.0x
#define SMeterLatency 3 //1 is 0.25 sec

//==============================================================================
// Hardware, Define PIN Usage
Expand Down
8 changes: 4 additions & 4 deletions ubitx_20/ubitx_20.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1000,10 +1000,10 @@ void initSettings(){
{
//Default Setting
arTuneStep[0] = 10;
arTuneStep[1] = 20;
arTuneStep[2] = 50;
arTuneStep[3] = 100;
arTuneStep[4] = 200;
arTuneStep[1] = 50;
arTuneStep[2] = 100;
arTuneStep[3] = 500;
arTuneStep[4] = 1000;
}

if (tuneStepIndex == 0) //New User
Expand Down
236 changes: 200 additions & 36 deletions ubitx_20/ubitx_lcd_1602p.ino → ubitx_20/ubitx_lcd_1602.ino
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#ifdef UBITX_DISPLAY_LCD1602P


//========================================================================
//Begin of TinyLCD Library by KD8CEC
//========================================================================
/*************************************************************************
LCD1602_TINY Library for 16 x 2 LCD
Referecnce Source : LiquidCrystal.cpp
KD8CEC
This source code is modified version for small program memory
from Arduino LiquidCrystal Library
I wrote this code myself, so there is no license restriction.
So this code allows anyone to write with confidence.
But keep it as long as the original author of the code.
DE Ian KD8CEC
**************************************************************************/
#define LCD_Command(x) (LCD_Send(x, LOW))
#define LCD_Write(x) (LCD_Send(x, HIGH))

//Define connected PIN
#define LCD_PIN_RS 8
#define LCD_PIN_EN 9
uint8_t LCD_PIN_DAT[4] = {10, 11, 12, 13};

// commands
//Common Defines *********************************************************
#define LCD_CLEARDISPLAY 0x01
#define LCD_RETURNHOME 0x02
#define LCD_ENTRYMODESET 0x04
Expand Down Expand Up @@ -85,6 +59,39 @@ uint8_t LCD_PIN_DAT[4] = {10, 11, 12, 13};
#define LCD_5x10DOTS 0x04
#define LCD_5x8DOTS 0x00

// flags for backlight control
#define LCD_BACKLIGHT 0x08
#define LCD_NOBACKLIGHT 0x00

//========================================================================
//Begin of TinyLCD Library by KD8CEC
//========================================================================

#ifdef UBITX_DISPLAY_LCD1602P
/*************************************************************************
LCD1602_TINY Library for 16 x 2 LCD
Referecnce Source : LiquidCrystal.cpp
KD8CEC
This source code is modified version for small program memory
from Arduino LiquidCrystal Library
I wrote this code myself, so there is no license restriction.
So this code allows anyone to write with confidence.
But keep it as long as the original author of the code.
DE Ian KD8CEC
**************************************************************************/

#define LCD_Command(x) (LCD_Send(x, LOW))
#define LCD_Write(x) (LCD_Send(x, HIGH))

#define UBITX_DISPLAY_LCD1602_BASE

//Define connected PIN
#define LCD_PIN_RS 8
#define LCD_PIN_EN 9
uint8_t LCD_PIN_DAT[4] = {10, 11, 12, 13};

void write4bits(uint8_t value)
{
for (int i = 0; i < 4; i++)
Expand Down Expand Up @@ -167,20 +174,176 @@ void LCD_CreateChar(uint8_t location, uint8_t charmap[])
for (int i=0; i<8; i++)
LCD_Write(charmap[i]);
}
#endif
//========================================================================
//End of TinyLCD Library by KD8CEC
//========================================================================

/*
#include <LiquidCrystal.h>
LiquidCrystal lcd(8,9,10,11,12,13);
*/
//SWR GRAPH, DrawMeter and drawingMeter Logic function by VK2ETA
#define OPTION_SKINNYBARS

//========================================================================
//Begin of I2CTinyLCD Library by KD8CEC
//========================================================================
#ifdef UBITX_DISPLAY_LCD1602I
#include <Wire.h>
/*************************************************************************
I2C Tiny LCD Library
Referecnce Source : LiquidCrystal_I2C.cpp // Based on the work by DFRobot
KD8CEC
This source code is modified version for small program memory
from Arduino LiquidCrystal_I2C Library
I wrote this code myself, so there is no license restriction.
So this code allows anyone to write with confidence.
But keep it as long as the original author of the code.
Ian KD8CEC
**************************************************************************/
#define UBITX_DISPLAY_LCD1602_BASE

#define En B00000100 // Enable bit
#define Rw B00000010 // Read/Write bit
#define Rs B00000001 // Register select bit

#define LCD_Command(x) (LCD_Send(x, 0))
#define LCD_Write(x) (LCD_Send(x, Rs))

uint8_t _Addr;
uint8_t _displayfunction;
uint8_t _displaycontrol;
uint8_t _displaymode;
uint8_t _numlines;
uint8_t _cols;
uint8_t _rows;
uint8_t _backlightval;

#define printIIC(args) Wire.write(args)

void expanderWrite(uint8_t _data)
{
Wire.beginTransmission(_Addr);
printIIC((int)(_data) | _backlightval);
Wire.endTransmission();
}

void pulseEnable(uint8_t _data){
expanderWrite(_data | En); // En high
delayMicroseconds(1); // enable pulse must be >450ns

expanderWrite(_data & ~En); // En low
delayMicroseconds(50); // commands need > 37us to settle
}

void write4bits(uint8_t value)
{
expanderWrite(value);
pulseEnable(value);
}

void LCD_Send(uint8_t value, uint8_t mode)
{
uint8_t highnib=value&0xf0;
uint8_t lownib=(value<<4)&0xf0;
write4bits((highnib)|mode);
write4bits((lownib)|mode);
}


// Turn the (optional) backlight off/on
void noBacklight(void) {
_backlightval=LCD_NOBACKLIGHT;
expanderWrite(0);
}

void backlight(void) {
_backlightval=LCD_BACKLIGHT;
expanderWrite(0);
}

void LCD1602_Init()
{
//I2C Init
_Addr = I2C_DISPLAY_ADDRESS;
_cols = 16;
_rows = 2;
_backlightval = LCD_NOBACKLIGHT;
Wire.begin();

delay(50);

// Now we pull both RS and R/W low to begin commands
expanderWrite(_backlightval); // reset expanderand turn backlight off (Bit 8 =1)
delay(1000);
//put the LCD into 4 bit mode
// this is according to the hitachi HD44780 datasheet
// figure 24, pg 46

// we start in 8bit mode, try to set 4 bit mode
write4bits(0x03 << 4);
delayMicroseconds(4500); // wait min 4.1ms

// second try
write4bits(0x03 << 4);
delayMicroseconds(4500); // wait min 4.1ms

// third go!
write4bits(0x03 << 4);
delayMicroseconds(150);

// finally, set to 4-bit interface
write4bits(0x02 << 4);

// finally, set # lines, font size, etc.
LCD_Command(LCD_FUNCTIONSET | LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS | LCD_2LINE);

// turn the display on with no cursor or blinking default
LCD_Command(LCD_DISPLAYCONTROL | LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF);

// clear it off
LCD_Command(LCD_CLEARDISPLAY); // clear display, set cursor position to zero
//delayMicroseconds(2000); // this command takes a long time!
delayMicroseconds(1000); // this command takes a long time!

LCD_Command(LCD_ENTRYMODESET | LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT);

backlight();
}

void LCD_Print(const char *c)
{
for (uint8_t i = 0; i < strlen(c); i++)
{
if (*(c + i) == 0x00) return;
LCD_Write(*(c + i));
}
}

void LCD_SetCursor(uint8_t col, uint8_t row)
{
LCD_Command(LCD_SETDDRAMADDR | (col + row * 0x40)); //0 : 0x00, 1 : 0x40, only for 16 x 2 lcd
}

void LCD_CreateChar(uint8_t location, uint8_t charmap[])
{
location &= 0x7; // we only have 8 locations 0-7
LCD_Command(LCD_SETCGRAMADDR | (location << 3));
for (int i=0; i<8; i++)
LCD_Write(charmap[i]);
}
#endif
//========================================================================
//End of I2CTinyLCD Library by KD8CEC
//========================================================================


//========================================================================
// 16 X 02 LCD Routines
//Begin of Display Base Routines (Init, printLine..)
//========================================================================
#ifdef UBITX_DISPLAY_LCD1602_BASE

//SWR GRAPH, DrawMeter and drawingMeter Logic function by VK2ETA
#define OPTION_SKINNYBARS

char c[30], b[30];
char printBuff[2][17]; //mirrors what is showing on the two lines of the display

Expand Down Expand Up @@ -589,9 +752,9 @@ void DisplayMeter(byte meterType, byte meterValue, char drawPosition)

byte testValue = 0;
char checkCount = 0;
char checkCountSMeter = 0;

int currentSMeter = 0;
//byte sMeterLevels[] = {0, 1, 4, 10, 18, 35, 63, 91, 117}; //John's default Value (divide / 4)
byte scaledSMeter = 0;

void idle_process()
Expand Down Expand Up @@ -621,10 +784,11 @@ void idle_process()
*/

//S-Meter Display
if ((displayOption1 & 0x08) == 0x08 && (sdrModeOn == 0))
if (((displayOption1 & 0x08) == 0x08 && (sdrModeOn == 0)) && (++checkCountSMeter > SMeterLatency))
{
int newSMeter;

checkCountSMeter = 0; //Reset Latency time

//VK2ETA S-Meter from MAX9814 TC pin / divide 4 by KD8CEC for reduce EEPromSize
newSMeter = analogRead(ANALOG_SMETER);

Expand Down
Loading

0 comments on commit 5611e1c

Please sign in to comment.