VFD brightness
Hi all friend, I need help,
Now I use Potentiometer (0~1023) and arduino uno and VFD 20 x 2 for my CMSP but I have the following problem,
I independently find the arduino code ( DSC-Bios to VFD, control VFD brightness),
How to merge the Potentiometer (0~1023) with VFD brightness code for DSC-Bios to VFD), and the VFD brightness code that have 4 degree for 100%, 75%, 50% and 25% brightness, may I use Potentiometer's range (0~255) for 25%, (256~511) for 50%, (512~767) for 75% and (768~1023) for 100% brightness? or any idea for 4 degree brightness with Potentiometer that similar as real cmsp's brightness function.
And may I control the turn on or off the Display used the code? I have attached some VFD menu and red high light it may useful.
:helpsmilie: Please help, Thank you
independently code as the following
<< DSC-Bios to VFD >>
#define DCSBIOS_IRQ_SERIAL
#include "DcsBios.h"
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void onCmsp1Change(char* newValue) {
lcd.setCursor(0, 0);
lcd.write(newValue[9]);
lcd.write(newValue[0]);
lcd.write(newValue[1]);
lcd.write(newValue[2]);
lcd.write(newValue[3]);
lcd.write(newValue[4]);
lcd.write(newValue[5]);
lcd.write(newValue[6]);
lcd.write(newValue[7]);
lcd.write(newValue[8]);
lcd.write(newValue[9]);
lcd.write(newValue[9]);
lcd.write(newValue[10]);
lcd.write(newValue[11]);
lcd.write(newValue[12]);
lcd.write(newValue[13]);
lcd.write(newValue[14]);
lcd.write(newValue[15]);
lcd.write(newValue[16]);
lcd.write(newValue[17]);
lcd.write(newValue[18]);
lcd.write(newValue[19]);
}
DcsBios::StringBuffer<19> cmsp1Buffer(0x1000, onCmsp1Change);
void onCmsp2Change(char* newValue) {
lcd.setCursor(0, 1);
lcd.write(newValue[0]);
lcd.write(newValue[1]);
lcd.write(newValue[2]);
lcd.write(newValue[3]);
lcd.write(newValue[4]);
lcd.write(newValue[5]);
lcd.write(newValue[6]);
lcd.write(newValue[7]);
lcd.write(newValue[8]);
lcd.write(newValue[9]);
lcd.write(newValue[9]);
lcd.write(newValue[10]);
lcd.write(newValue[11]);
lcd.write(newValue[12]);
lcd.write(newValue[13]);
lcd.write(newValue[14]);
lcd.write(newValue[15]);
lcd.write(newValue[16]);
lcd.write(newValue[17]);
lcd.write(newValue[18]);
lcd.write(newValue[19]);
}
DcsBios::StringBuffer<19> cmsp2Buffer(0x1014, onCmsp2Change);
void setup() {
DcsBios::setup();
lcd.begin(20, 2);
lcd.clear();
}
void loop() {
DcsBios::loop();
}
<< control VFD brightness >>
/*
LiquidCrystal Library - demo
Extension to control brightness VFD
*/
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// Adds definitions for VFD:
#define VFD_25pc 0x03
#define VFD_50pc 0x02
#define VFD_75pc 0x01
#define VFD_100pc 0x00
void vfd_brightness(int brightness) {
// unfortunately lcd._displayfunction is private so we've to redefine it
int _displayfunction = LCD_4BITMODE | LCD_2LINE | LCD_5x8DOTS;
lcd.command(LCD_FUNCTIONSET | _displayfunction | brightness);
}
void setup() {
// set up the LCD's number of rows and columns:
lcd.begin(2, 16);
lcd.print("hello, world!");
}
void loop() {
vfd_brightness(VFD_100pc);
delay(200);
vfd_brightness(VFD_75pc);
delay(200);
vfd_brightness(VFD_50pc);
delay(200);
vfd_brightness(VFD_25pc);
delay(200);
vfd_brightness(VFD_50pc);
delay(200);
vfd_brightness(VFD_75pc);
delay(200);
}
==========================
VFD menu as the following
4-4-6. FUNCTION SET
RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
0 0 0 0 1 DL N × BR1 BR0
×=don’t care
This instruction sets the width of the data bus for the parallel interface modes, the
number of display lines, and the luminance level (brightness) of the VFD. DDRAM,
CGRAM, and AC contents are not affected by this instruction.
DL = 0 :Sets the data bus width for the parallel interface modes to 4-bit (DB7-DB4).
DL = 1 :Sets the data bus width for the parallel interface modes to 8-bit (DB7-DB0).
N = 0 : Sets the number of display lines to 1 (this setting is not recommended).
N = 1 : Sets the number of display lines to 2
BR1, BR0 = 0,0: Sets the luminance level to 100%.
0,1: Sets the luminance level to 75%.
1,0: Sets the luminance level to 50%.
1,1: Sets the luminance level to 25%.
4-5 RESET CONDITIONS
After a power-up reset, the module initializes to the following conditions:
1) All DDRAM locations are set to 20H (character code for a space).
2) The AC is set to DDRAM address 00H (i.e. sets cursor position to 00H).
3) The relationship between DDRAM addresses and character positions on the VFD is set
to the non-shifted position.
4) Entry Mode Set instruction bits:
I/D = 1: The AC increments after each DDRAM or CGRAM access. If S=1, the
information on the display shifts to the left by one character position after
each DDRAM write.
S = 0: The display shift function is disabled.
5) Display On/Off Control instruction bits:
D = 0: The display is off (display blank).
C = 0: The cursor is off.
B = 0: The blinking character function is disabled.
6) Function Set instruction bits:
DL = 1: Sets the data bus width for the parallel interface modes to 8-bit (DB7-DB0).
N = 1: Number of display lines set to 2.
BR1,BR0=0,0: Sets the luminance level to 100%.
Thank you for your help.