' **************************************************************** ' * File: gmbiote.bas - Ver. 1.1 * ' * Compiler: PIC Basic PRO * ' * IDE: MicroCode Studio Plus * ' * Compiler Version: 2.45 * ' * Boards: GMM 4620 + GMB HR168 * ' * GRIFO(R) via Dell'Artigiano 8/6 * ' * 40016 S. Giorgio di Piano (BO) * ' * Tel. +39 051 892052 Fax. +39 051 893661 * ' * http://www.grifo.com http://www.grifo.it * ' * by Graziano Gaiba del 01.02.05 * ' **************************************************************** ' ' This demo allows to use immediatly TTL I/O digital lines available ' on CN7. The list of lines existing is printed. After selecting the ' line to use it can be managed as input (its status is shown ' continuously on console) or as output (setting it high or low). ' Should the line selected be associated to Real Time Clock, this ' peripheral manages it. ' ' ' Rel 1.1 - by Graziano Gaiba ' Demo program of TTL I/O digital lines of GMB HR168 driven by ' Mini Module GMM 4620 ' ' ' ******************** Compiler definitions ********************** ' DEFINE OSC 10 ' Oscillator frequency 9,8304 MHz DEFINE HSER_RCSTA 90h ' Enable EUSART serial receiver DEFINE HSER_TXSTA 20h ' Enable EUSART serial transmitter DEFINE HSER_BAUD 19200 ' Baud Rate ' ' ******************* Constants declaration ********************** ' RTCSLA con $A0 ' ' ******************** Variables declaration ********************* ' ' Generic variables i var byte scelta var byte di var byte do var byte ' ' Used by I/O management procedures port_val var byte ' Value read or to be written to the I/O ' ' ' '************************** Main Program ******************************* ' main: gosub Init_cpu ' Turn OFF relays port_val = 0 gosub set_relays for_ever: gosub clrscr hserout ["TTL I/O on CN7 demo Rel 1.1 for GMM 4620 rel 120304 and GMB HR168 rel 110104", 13, 10, 13, 10] hserout ["If selected as input, its status in shown continuously, press a key to exit", 13, 10] hserout ["If selected as output, press 1 to set, 0 to reset, any other number to exit", 13, 10, 13 ,10] hserout ["1) pin 2 of CN7", 13, 10] ' RE0 hserout ["2) pin 3 of CN7", 13, 10] ' RE1 hserout ["3) pin 4 of CN7", 13, 10] ' /INTRTC hserout ["4) pin 6 of CN7", 13, 10] ' RC2 hserout ["5) pin 8 of CN7", 13, 10] ' RA5 hserout [13, 10, "Choice: "] input_scelta: hserin [dec1 scelta] if scelta < 1 and scelta > 5 then input_scelta hserout [dec1 scelta, 13, 10] hserout [13, 10] hserout ["1) Input", 13, 10] hserout ["2) Output", 13, 10] input_scelta_dir: hserin [dec1 i] if i < 1 and i > 2 then input_scelta_dir if i = 1 then hserout [13, 10, "Input", 13, 10] else hserout [13, 10, "Output", 13, 10] endif scelta_loop: hserout [13, 10] ' pin 2 of CN7 - RE0 if scelta = 1 then if i = 1 then trise.0 = 1 scelta_loop_1: hserout ["Status: ", dec1 porte.0, 13] hserin 50, scelta_loop_1, [di] else trise.0 = 0 hserout ["Status: "] hserin [dec1 do] hserout [dec1 do] if do <> 0 and do <> 1 then for_ever porte.0 = do goto scelta_loop endif endif ' pin 3 of CN7 - RE1 if scelta = 2 then if i = 1 then trise.1 = 1 scelta_loop_2: hserout ["Status: ", dec1 porte.1, 13] hserin 50, scelta_loop_2, [di] else trise.1 = 0 hserout ["Status: "] hserin [dec1 do] hserout [dec1 do] if do <> 0 and do <> 1 then for_ever porte.1 = do goto scelta_loop endif endif ' pin 4 of CN7 - /INTRTC if scelta = 3 then hserout ["Pin 4 is connected to Real Time Clock interrupt. It can:", 13, 10] hserout ["generate square waves; activate every enth,second,minute,hour,day", 13, 10] hserout ["or at a preset time.", 13, 10] hserout ["LED LD28 shows its status.", 13, 10] gosub wait_key endif ' pin 6 of CN7 - RC2 if scelta = 4 then if i = 1 then trisc.2 = 1 scelta_loop_3: hserout ["Status: ", dec1 portc.2, 13] hserin 50, scelta_loop_3, [di] else trisc.2 = 0 hserout ["Status: "] hserin [dec1 do] hserout [dec1 do] if do <> 0 and do <> 1 then for_ever portc.2 = do goto scelta_loop endif endif ' pin 8 of CN7 - RA5 if scelta = 5 then if i = 1 then trisa.5 = 1 scelta_loop_4: hserout ["Status: ", dec1 porta.5, 13] hserin 50, scelta_loop_4, [di] else trisa.5 = 0 hserout ["Status: "] hserin [dec1 do] hserout [dec1 do] if do <> 0 and do <> 1 then for_ever porta.5 = do goto scelta_loop endif endif goto for_ever end ' ' **************** Procedures definition ****************** ' ' ' CPU and signals directions initialization Init_cpu: ADCON1=$0f ' Imposta come I/O digitale i pin AN0..12 CMCON=$07 ' Imposta come I/O digitale RA0..4 ' Optocoupled Inputs of CN1 are: ' IN1-1 <-> RA0 ' IN2-1 <-> RA1 ' IN3-1 <-> RB0 ' IN4-1 <-> RB1 ' IN5-1 <-> RA4 ' IN6-1 <-> RC0 ' IN7-1 <-> RC1 ' IN8-1 <-> RC5 trisa.0 = 1 trisa.1 = 1 trisa.4 = 1 trisb.0 = 1 trisb.1 = 1 trisc.0 = 1 trisc.1 = 1 trisc.5 = 1 ' Optocoupled Inputs of CN2 are: ' IN1-2 <-> RD0 ' IN2-2 <-> RD1 ' IN3-2 <-> RD2 ' IN4-2 <-> RD3 ' IN5-2 <-> RD4 ' IN6-2 <-> RD5 ' IN7-2 <-> RD6 ' IN8-2 <-> RD7 trisd = $ff ' Relay outputs of CN3 are: ' OUT A1 <-> RB4 ' OUT A2 <-> RB5 ' OUT B1 <-> RB6 ' OUT B2 <-> RB7 ' OUT C1 <-> RB3 ' OUT C2 <-> RB2 trisb = trisb & $03 ' Relay outputs of CN4 are: ' OUT D1 <-> RA3 ' OUT D2 <-> RC2 (J10 in position 3-4) trisa.3 = 0 trisc.2 = 0 return ' ' ' Clear screen, sending 25 times CR + LF. clrscr: for i= 0 to 24 hserout [13, 10] next i return ' ' ' Asks for a key press wait_key: hserout ["Press a key..."] wait_key_loop: hserin 1, wait_key_loop, [i] return ' ' ' Procedure to set the status of the relays on connectors CN3 and CN4. ' According to the bits of port_val, each relay is turned ON ' (contact closed) or OFF (contact open). ' Bits of port_val have this meanging: ' -- CN3 ' port_val.0 drives relay OUT A1 ' port_val.1 drives relay OUT A2 ' port_val.2 drives relay OUT B1 ' port_val.3 drives relay OUT B2 ' port_val.4 drives relay OUT C1 ' port_val.5 drives relay OUT C2 ' -- CN4 ' port_val.6 drives relay OUT D1 ' port_val.7 drives relay OUT D2 ' ' Each bit has the following meaning: ' bit Meaning ' 0 Relay turned OFF (contact open) ' 1 Relay turned ON (contact closed) set_relays: ' Relays are driven in complemented logic, so port_val must be ' complemented too port_val = port_val ^ $ff portb.4 = port_val.0 portb.5 = port_val.1 portb.6 = port_val.2 portb.7 = port_val.3 portb.3 = port_val.4 portb.2 = port_val.5 porta.3 = port_val.6 portc.2 = port_val.7 return