Thanks for the links, I found the third one to be the most help so far. The HSERIN info looks great too, I'm going to have to do some reading tomorrow on the defines.
I've updated the code again a bit. It's now broken. I've set it up so that I read the lower 4 bits of PORTB and if they are greater than 0 a button must have been pushed so the data is sent via SEROUT. I've also set the TRIS registers, although I may have set them wrong since the chips no longer wait 2 seconds to light the Green Status LED, they just turn on right away. Also 3/4 of the indicator LEDs come on automatically and pushing buttons does nothing.
I'm certain it's something to do with the TRIS registers but I haven't done anything different from the example in link 3 (that I can see) except to use BIN instead of HEX.
It's late, I might be missing something obvious, I'll check to code again tomorrow night. For now I'll post what I have.
andCode:'**************************************************************** '* Title : One Wire Serial Control * '* File : Output17.pbp * '* Author : Greensasquatch * '* Date : 10/13/2008 * '* Chip : PIC16F628A * '* Version : 1.7 * '* Notes : To output a number corresponding to which button * '* : was pressed via serial communication * '**************************************************************** '* This Program is part 1 of 2. The other half receives a '* number and lights a corresponding LED. '**************************************************************** '* REVISIONS: '* -comparators disabled '* -read RB0-RB3 to a byte and send this '* -TRIS registers set '**************************************************************** '* '* Connections are as follows: '* '* N/C -01-|####|-18- N/C '* N/C -02-|####|-17- SEROUT Line '* N/C -03-|####|-16- N/C '* MCLR 10K to V+ -04-|####|-15- N/C '* Gnd -05-|####|-14- V+ '* Butt1 -06-|####|-13- N/C '* Butt1 -07-|####|-12- N/C '* Butt1 -08-|####|-11- N/C '* Butt1 -09-|####|-10- Green Power LED '* '**************************************************************** INCLUDE "MODEDEFS.BAS" 'uses internal oscillator (should use crystal but ran out) @ DEVICE pic16F628A, INTRC_OSC_NOCLKOUT CMCON = 7 'disable comparators TRISB = %00001111 'RB0-RB3 Inputs, all others output TRISA = 0 'set portA as output GreenLED var PORTB.4 'alias RB4 to GreenLED Butt1 var PORTB.0 'alias Butt1 to RB0 Butt2 var PORTB.1 'alias Butt2 to RB1 Butt3 var PORTB.2 'alias Butt3 to RB2 Butt4 var PORTB.3 'alias Butt4 to RBZ ButStat Var Byte 'Variable for button status Pause 2000 'wait to begin high greenled 'turn on status light Loop: ButStat = PORTA & %00001111 'isolate lower 4 bits of portA & write to ButStat 'If ButStat has value greater than 0, then buttons must have been pushed, 'then send 9 and the value of ButStat IF Butstat > 0 THEN SEROUT PORTA.0,T1200,[9,Butstat] GOTO LOOP end
Code:'**************************************************************** '* Title : One Wire Serial Control * '* File : Input17.pbp * '* Author : Greensasquatch * '* Date : 10/13/2008 * '* Chip : PIC16F628A * '* Version : 1.7 * '* Notes : To read a number via serial communication and * '* : light a corresponding LED * '**************************************************************** '* This Program is part 2 of 2. The other half sends a '* number corresponding to a button state. '**************************************************************** '* REVISIONS: '* -comparators disabled, turn out lights when no signal '* -receive a byte and output to portA '* -set TRIS registers '**************************************************************** '* '* Connections are as follows: '* '* LED3 -01-|####|-18- LED2 '* LED4 -02-|####|-17- LED1 '* N/C -03-|####|-16- N/C '* MCLR 10K to V+ -04-|####|-15- N/C '* Gnd -05-|####|-14- V+ '* Serial In -06-|####|-13- N/C '* Green Power LED -07-|####|-12- N/C '* N/C -08-|####|-11- N/C '* N/C -09-|####|-10- N/C '* '**************************************************************** INCLUDE "MODEDEFS.BAS" 'uses internal oscillator (should use crystal but ran out) @ DEVICE pic16F628A, INTRC_OSC_NOCLKOUT CMCON=7 'disable comparators TRISA = %11110000 'set RA0-RA3 as output, rest as input TRISB = %00000001 'set RB0 as input, rest as output GreenLED var PORTB.1 'alias RB1 to GreenLED NET var byte 'holding variable for input Pause 2000 'wait to begin high greenled 'turn on status light Loop: 'waits for a "9" and writes the next value to NET 'turn off LEDs if no signal after 200ms SERIN PORTB.0,T1200,200,OffLed,[9],NET PORTA = NET 'set PORTA to NET value GOTO LOOP OffLED: PORTA=0 'set porta pins low Goto Loop end




Bookmarks