Okay so that wasn't too hard.
The master transmitter now uses pretty much all of the ram available on the 16F88 as a buffer. Allowing 16 commands to be stored and transmitted from 2 seperate buffers.
I am pretty sure I will not be needing more then that for this project and so here it is.
:MSmaster:
Code:'**************************************************************** '* Name : MSERVMASTER.BAS * '* Author : Joseph Dattilo * '* Notice : Copyright (c) 2007 Joseph Dattilo * '* : All Rights Reserved * '* Date : 5/25/2007 * '* Version : 1.0 * '* Notes : * '* : * '**************************************************************** define OSC 8 OSCCON = %1111110 ' sets internal osc to run at 8MHZ '----------turn analog on porta off, and use as digital input/output '----------this is used to allow serial input on the A bus. CMCON = 7 'Comparators OFF ANSEL = 0 'A/D OFF -- Port pins all digital '---------- '---**Pins rsoutpin var porta.0 rsinpin var porta.1 picinpin var portb.4 picoutpin var portb.5 porta=0 portb=0 '---vars temp var byte qued var byte outqued var byte message var byte[24] '-up to 8 commands can be buffered in each que array adding up to 16 altogether. que var byte[96] que2 var byte[96] '--------------- qued = 0 'set number in que to 0 goto pcin '############################## pc recieve ################################ 'que up messages from pc '########################################################################## pcin: '---- let pc know we are ready to recieve message. serout2 rsoutpin, 16468, ["waiting!"] 'call for data '---- ready to recieve message serin2 rsinpin, 16468, [str message\24] '------------------------------------------------------------------------ 'compare both arrays checking for bad data if data bad request it again. for temp = 0 to 11 : if message[temp] <> message[temp+12] then goto baddata next temp '------------------------------------------------------------------------ serout2 rsoutpin, 16468, [str message\12] 'send confirmation of reciept. '------------------inque----------------- for temp = 0 to 11 if qued<8 then 'add to first que que[(12*qued)+temp]=message[temp] else 'add to second que que2[(12*(qued-8))+temp]=message[temp] endif next temp if qued>7 then serout2 rsoutpin, 16468, ["Que 1:",str que\96, _ "Que 2:",str que2\(12*(qued-8)+12)] else serout2 rsoutpin, 16468, ["Que 1:",str que\(12*qued+12)] 'display all in que endif '---------------------------------------- if message[11] = "n" and qued<15 then serout2 rsoutpin, 16468, ["still more commands!?"] 'debug statement qued=qued+1 'go to next position in que goto pcin 'request the data for the next item. else outqued = 0 'set picout que start position to 0 (first item in que first) goto picout 'we are ready to command the servo controller. endif '------------------------- 'where bad data takes you. baddata: serout2 rsoutpin, 16468, ["bad data!"] goto pcin '------------------------- '############################## pic transmit ############################# '---- picout procedure waits for high on picinpin and then transmits data '######################################################################### picout: '---------------------unque next item into message array for temp = 0 to 11 if outqued<8 then 'add to first que message[temp]=que[(12*outqued)+temp] message[temp+12]=que[(12*outqued)+temp] else 'add to second que message[temp]=que2[(12*(outqued-8))+temp] message[temp+12]=que2[(12*(outqued-8))+temp] endif next temp '------------------------------------------------------- input picinpin while picinpin = 0 pause 1 wend serout2 picoutpin, 16468, [str message\24] pause 7 if picinpin = 1 then 'checks if data was recieved goto picout 're-send until recieved endif serout2 rsoutpin, 16468, ["SUCCESS|",str message\12,"|"] 'tell computer if outqued < qued then outqued = outqued +1 'move to next qued item goto picout 'proceed to transmit it. else serout2 rsoutpin, 16468, ["|ALL",DEC (qued+1),"items transmitted succesfully|"] qued=0 goto pcin endif end
As a note no changes need be made to the slave from last version for cross compatability.




Bookmarks