Clock connection to DS1802 from 16F877A
I thought this would be a simple solution for someone more experienced than me before I breadboard a mess. It is not a programming question, but I need the circuit correct before I can test my programming.
I am using a 16F877A as the brains for an IR receiver in a preamp. In conjunction with the 16F877A, I am using a Dallas Semiconductor (Maxim) DS1802, dual-digital potentiometer. The DS1802 has a "RST" (Serial Port Reset Input) pin that must be "high" to trigger an internal read and write routine of a "Word" (I’ve got this covered). In addition, however, the DS1802 has a "CLK" (Serial Port Clock Input) pin, which I am almost 100% sure needs the clock speed from the 16F877A.
I have a 20MHz crystal connected to pins 13 and 14 of the 16F877A with paralleled 22pf caps to ground.
My question is, can I just simply connect the "CLK" pin of the DS1802 to pin 14 (OSC2/CLKOUT) of the 16F877A or is it more complicated?
If I must use a separate pin of the 16F877A, how do I place the clock speed on the pin so the DS1802 can see 20MHz?
Thanks
Ken Klausner
Easier than I thought it would be
I didn't realize that just designating a "CLK" pin on the 16F877A is all that was needed. I was under the impression that I had to somehow place a square wave on the "CLK" pin for the DS1802's reference. I used a 4 MHz crystal on the 16F877A. The following relevant code works great for reading pot values from the DS1802 and displaying the pot values on an Optrex LCD:
INCLUDE "modedefs.bas"
@ DEVICE XT_OSC, WDT_OFF, LVP_OFF, BOD_OFF, PWRT_ON, PROTECT_OFF
DEFINE LCD_DREG PORTA ' RA to LCD data port
DEFINE LCD_DBIT 0 ' Starting data bit on A0 & last on A3
DEFINE LCD_BITS 4 ' Set 4-bit data bus width
DEFINE LCD_RSREG PORTA ' Set LCD register select port to A
DEFINE LCD_RSBIT 4 ' Set A4 to register select pin
DEFINE LCD_EREG PORTE ' Set LCD enable to port E
DEFINE LCD_EBIT 0 ' Set E0 to LCD enable pin
DEFINE LCD_LINES 4 ' LCD is a 4 line display
DEFINE LCD_COMMANDUS 2000 ' Set LCD command delay time in uS
DEFINE LCD_DATAUS 50 ' Set LCD data delay time in uS
ADCON1 = 7 ' Digital I/O for RA & RE
INTCON.7 = 1 ' Enable all unmasked interrupts (GIE)
TRISB = 255 ' All PORTB pins as inputs for panel switches
OPTION_REG.7 = 0 ' Enable all PORTB internal pull-ups
RST var PORTD.5 ' Set high to read potentiometer settings
RST = 0
CLK var PORTE.1 ' Clock DS1802 to read potentiometer settings
ReadPots var PORTE.2 ' Read potentiometer settings
LPot var byte ' Left channel
RPot var byte ' Right channel
pause 500
LCDOUT 254, 12 ' Turn cursor off & display on
lcdout 254, 1 ' Clear display
pause 200
lcdout 254, 135, "Volume"
gosub update_lcd
MAIN:
if PORTB <> 255 THEN
endif
GOTO MAIN
UPDATE_LCD:
RST = 1
shiftin readpots, clk, LSBPRE, [lpot, rpot]
rst = 0
lpot = lpot & %00111111
rpot = rpot & %00111111
if lpot < 10 then
lcdout 254, 194, "L:-", #lpot, "db ", " R:-", #rpot, "db "
else
lcdout 254, 194, "L:-", #lpot, "db", " R:-", #rpot, "db "
endif
return