Sorry I can't give you "all" the code, but I can give you enough to show how easy it is.
This was done for a customer. It's for a hand-held RF wireless control terminal. This small section shows how to control the DS1804 digital pot. The digital pot controls the hand-held terminals LCD contrast.
The DS1804 POT wiper position is stored in internal EEPROM. Storing the wiper position allows the terminals LCD contrast to be the same after power off and on conditions. I.E. the terminal always remembers the LCD contrast settings.
CS VAR PortC.2 ' Pot chip select/control
INC VAR PortC.0 ' Pot wiper increment, 0=INC, 1=Disable INC.
UD VAR PortC.1 ' Pot Up/Down select 0=Down, 1=Up
This prints a menu on the LCD waiting for user input to adjust contrast, turn on or off the LCD backlight, etc,,. and adjusts the contrast of the LCD connected to the digital pot.
AdjCont:
lcdout CMD,CLR
LCDOUT CMD,L1," ** LCD Adjust ** "
LCDOUT CMD,L2," 1=Darken 2=Lighten" ' 1=Key #11, 2=Key #6
lcdout CMD,L3," 3=LED ON 4=LED OFF" ' 3=Key #1, 4-Key #12
LCDOUT CMD,L4," ESC=Back Ent=Save " ' ESC=Key #15, Ent=Ket #10
Adj:
gosub GetKey
if KeyIn = 15 then Mode1
if KeyIn = 11 then
CS = 0 : UD = 0 ' 0=Dark contrast
LOW INC : HIGH INC
pause 250
endif
if KeyIn = 6 then
CS = 0 : UD = 1 ' 1=Light contrast
LOW INC : HIGH INC
pause 250
endif
if (Mode=1) and (KeyIn=1) then BKLITE=TRUE
if (Mode=1) and (KeyIn=12) then BKLITE=FALSE
if KeyIn = 10 then Save
Goto Adj
Save: ' Store wiper settings in DS1804 internal EEPROM
Mode=1
HIGH INC : CS=0 : CS=1 : CS=0
lcdout CMD,CLR
lcdout CMD,L2," * Saving Settings *"
PAUSE 1000
GOTO OtherStuff
If you download & review the DS1804 datasheet, you'll understand how all this neat stuff's working. It's really very simple.




Bookmarks