'b0 \_ = varible 'b1 / w0 = counter 'b2 \_ = character 'b3 / w1 = cursor start posistion 'b4 \_ = cursor end posistion 'b5 / w2 = keypad 'b6 \_ = \ 'b7 / w3 = / word variable 'b8 \_ = servo posistion / motor speed 'b9 / w4 = motor speed 'b10\_ = 1s / end character 'b11/ w5 = 10s 'b12\_ = 100s 'b13/ w6 = 1000s 'poke $C0 = b6 - 7th digit in display current servo / motor 'poke $C1 = b7 'poke $C2 = 'poke $C3 = screen High Address 'poke $C4 = b0 'poke $C5 = b1 start: setint %00000000,%00000001 'for IR input let dirsc = %11100001 'set input / output pins on port C let infra = 0 let pins = 0 high portc 0 'latch enable low portc 0 'latch disable (stop all motors) high portc 5 'ce disable low portc 7 'wr enable i2cslave %11010000, i2cslow, i2cbyte'set for i2c RTC readi2c 7,(b2) 'check if clock is set - $10 if b2 = $10 then set_i2cprom ' (sec,min,hrs,day,dat,mth,yer,cnt) writei2c 0,($00,$00,$00,$05,$08,$11,$05,$10)'set clock set_i2cprom: i2cslave %10100000, i2cfast, i2cword'set for i2c eeprom 'pause 3000 'wait for i2cslaves '------------------| Display EYE graphics |------------------------ init_screen: poke $C3,$80 'screen High Address let b3 = $00 '1st address in eeprom let b4 = $0C 'last address in eeprom gosub init_disp 'set graphics mode let b3 = $00 'set cursor position gosub cursor_pos let w0 = $400 'set begining of graphic data get_graphics: readi2c w0,(b6,b7,b8,b9,b10,b11,b12,b13) let pins = b6 low portc 5 'ce high portc 5 'ce let pins = b7 low portc 5 'ce high portc 5 'ce let pins = b8 low portc 5 'ce high portc 5 'ce let pins = b9 low portc 5 'ce high portc 5 'ce let pins = b10 low portc 5 'ce high portc 5 'ce let pins = b11 low portc 5 'ce high portc 5 'ce let pins = b12 low portc 5 'ce high portc 5 'ce let pins = b13 low portc 5 'ce high portc 5 'ce let w0 = w0 + 8 if w0 < $7FF then get_graphics gosub cancel_auto 'cancel auto byte increment snd: high portc 7 'wr disable sound 5,(79,20,110,20,79,20,93,20,104,32) low portc 7 'wr enable pause 400 '------------------| Display MAIN screen |-------------------------' poke $C3,$00 'screen High Address let b3 = $10 '1st address in eeprom let b4 = $1D 'last address in eeprom gosub init_disp 'set text mode disp: 'display main screen let infra = 0 let b3 = $00 'set cursor posistion let w0 = $100 'begining of text data let b4 = $80 'display 128 bytes gosub display '">BiOS JR 3.1 M1<----------------4MHz 32KF 2K ROM" 'display " HRD USR DEMO" '-------------------------| 1ST MENU |-------------------------------' chk_key: gosub key_pad branch b5,(info,hrd,usr,demo) pause 100 goto chk_key info: let b3 = $00 'set cursor posistion let w0 = $180 'begining of text data let b4 = $80 'display 48 bytes gosub display 'display " Designed by Ivan Neubronner Thomas Braunl" fourth_key: gosub get_time readadc 1,b5 if infra = 4 then disp if b5 > 30 and b5 < 220 then disp goto fourth_key hrd: let b3 = $50 'set cursor posistion let w0 = $200 'begining of text data let b4 = $30 'display 48 bytes gosub display 'display "SET HDT IO END" hrd_key: gosub key_pad branch b5,(setup,hdt,io,disp) pause 100 goto hrd_key '-----------------------| SETUP |--------------------------------' setup: let b3 = $50 'set cursor posistion let w0 = $390 'begining of text data let b4 = $30 'display 48 bytes gosub display 'display "SER RMT CLK END" setup_key: gosub key_pad branch b5,(serial,rmt,clock,hrd) pause 100 goto setup_key '-----------------------| IR |-------------------------------' ir: let infra = 0 let w4 = 0 let b3 = $50 'set cursor posistion let w0 = $2C0 'begining of text data let b4 = $30 'display 48 bytes gosub display 'display "INRARED" writei2c $20,("D",$20,$20,$20) nxt_ir: if w4 = infra then nxt_ir let w4 = infra gosub digits 'display ir value if infra = 17 then io readadc 1,b5 if b5 > 30 and b5 < 220 then io 'goto io screen goto nxt_ir '-----------------------| SERIAL |-------------------------------' serial: goto setup '-----------------------| RMT |--------------------------------' rmt: goto setup '--------------------------| IO |--------------------------------' io: let b3 = $50 'set cursor posistion let w0 = $260 'begining of text data let b4 = $30 'display 48 bytes gosub display 'display "DIN IR ADC END" io_key: gosub key_pad branch b5,(din,ir,adc,hrd) pause 100 goto io_key '-----------------------| DIN |--------------------------------' din: let b3 = $50 'set cursor posistion let w0 = $290 'begining of text data let b4 = $30 'display 48 bytes gosub display 'display "D0 to D5" get_input: if pin1 = 0 then b1_zero let b1 = "1" goto pin_2 b1_zero: let b1 = "0" pin_2: if pin2 = 0 then b13_zero let b13 = "1" goto pin_3 b13_zero: let b13 = "0" pin_3: if pin3 = 0 then b12_zero let b12 = "1" goto pin_4 b12_zero: let b12 = "0" pin_4: if pin4 = 0 then b11_zero let b11 = "1" goto pin_5 b11_zero: let b11 = "0" pin_5: if pin5 = 0 then b10_zero let b10 = "1" goto last_one b10_zero: let b10 = "0" last_one: writei2c $20,($35,$20,$20,b1,b13,b12,b11,b10) let b3 = $57 'set cursor posistion let w0 = $20 'begining of text data let b4 = $08 'display 48 bytes gosub display if infra = 4 then io readadc 1,b5 if b5 > 30 and b5 < 220 then io goto get_input '-----------------------| CLOCK |--------------------------------' clock: let b3 = $50 'set cursor posistion let w0 = $3C0 'begining of text data let b4 = $30 'display 48 bytes gosub display 'display " + - NEXT END" writei2c $20,($20,$20,$20,$20) let w0 = $A0 'begining of text data poke $C4,b0 poke $C5,b1 poke $C0,1 let w4 = 0 clk_key: gosub key_pad branch b5,(plus3,minus3,nxt3,setup) pause 100 goto clk_key plus3: peek $C0,b6 ' Sec Mi Hr D Da Mo Yr lookup b6,(59,59,23,7,31,12,99),b2 'set max limit for values let b8 = b8 + 1 max b2 goto set_time minus3: if b8 = 0 then set_time let b8 = b8 - 1 goto set_time nxt3: pause 100 peek $C0,b6 let b6 = b6 + 1 if b6 = 7 then clock poke $C0,b6 let b3 = $50 'set cursor posistion peek $C4,b0 peek $C5,b1 let w0 = w0 + 16 poke $C4,b0 poke $C5,b1 let b4 = $07 'display 7 bytes gosub display goto clk_key set_time: gosub digits let b0 = b8 / 10 'MSB let b1 = b0 * 10 let b1 = b8 - b1 let b0 = b0 * 16 let b2 = b0 + b1 i2cslave %11010000, i2cslow, i2cbyte'set for i2c RTC peek $C0,b6 writei2c b6,(b2) pause 300 i2cslave %10100000, i2cfast, i2cword'set for i2c eeprom goto clk_key '-----------------------| ADC |--------------------------------' adc: let b3 = $50 'set cursor posistion let w0 = $360 'begining of text data let b4 = $30 'display 48 bytes gosub display 'display "ADC IN" menu 'display "KEY-TST NEXT END" menu let b6 = 255 '255 + 1 = 0 let w4 = 0 adc_key: let b6 = b6 + 1 if b6 = 8 then last_number3 if b6 = 4 then make_5 goto show_digit4 make_5: let b6 = 5 goto show_digit4 last_number3: let b6 = 0 show_digit4: let b7 = b6 + $30 'change to ASCII readadc10 b6,w4 writei2c $20,($20,b7,$20,$20) poke $C0,b6 gosub digits peek $C0,b6 if infra = 4 then io readadc 1,b5 if b5 > 30 and b5 < 70 then io 'refresh screen if b5 > 80 and b5 < 120 then adc_key'next key goto show_digit4 '----------------------| HDT MENU |------------------------------' hdt: let infra = 0 let b3 = $50 'set cursor posistion let w0 = $230 'begining of text data let b4 = $30 'display 48 bytes gosub display 'display "SERV MOT SND END" hdt_key: gosub key_pad branch b5,(serv,mot,snd,hrd) pause 100 goto hdt_key '--------------------| SERVO MENU |------------------------------' serv: let b3 = $50 'set cursor posistion let w0 = $300 'begining of text data let b4 = $30 'display 48 bytes gosub display 'display "SERVO 1" menu let b6 = 0 let b7 = 0 let b8 = 152 let b9 = 0 pwmout 1,255,0 'pwm1 off pwmout 2,255,0 'pwm2 off serv_key: gosub key_pad branch b5,(plus,minus,nxt,hdt) pause 100 goto serv_key plus: let infra = 0 high portc 0 'latch enable let b8 = b8 + 5 max 220 servo b6,b8 pause 100 low portc 0 'latch disable low b6 'disable servo drive goto show_digit minus: let infra = 0 high portc 0 'latch enable let b8 = b8 - 5 min 75 servo b6,b8 pause 100 low portc 0 'latch disable low b6 'disable servo drive goto show_digit nxt: let infra = 0 let b8 = 152 let b6 = b6 + 1 if b6 = 8 then last_number goto show_digit last_number: let b6 = 0 show_digit: let b7 = b6 + $31 'change to ASCII & inc by 1 writei2c $20,($20,b7,$20,$20) poke $C0,b6 gosub digits peek $C0,b6 goto serv_key '------------------------| MOTOR MENU |-----------------------------' mot: let b3 = $50 'set cursor posistion let w0 = $330 'begining of text data let b4 = $30 'display 16 bytes gosub display 'display "MOTOR A" menu let b6 = 1 'turn on motor A let b7 = "+" 'clockwise rotation of motor let w4 = 0 mot_key: gosub key_pad branch b5,(plus2,minus2,nxt2,mot_off) pause 100 goto mot_key plus2: let infra = 0 high portc 0 'latch enable let pins = b6 'select motor let w4 = w4 + 100 max 1023 if b6 > 8 then next_driver pwmout 1,255,w4 'pwm1 goto show_digit2 minus2: let infra = 0 high portc 0 'latch enable let pins = b6 'select motor if w4 < 100 then make_zero let w4 = w4 - 100 if b6 > 8 then next_driver pwmout 1,255,w4 'pwm1 goto show_digit2 make_zero: let w4 = 0 pwmout 1,255,w4 'pwm1 goto show_digit2 next_driver: pwmout 2,255,w4 'pwm2 goto show_digit2 nxt2: pwmout 1,255,0 'pwm1 off pwmout 2,255,0 'pwm2 off let infra = 0 let w4 = 0 let b6 = b6 * 2 if b6 = 0 then last_number2 '128 * 2 = 0 byte wrap around if b7 = "-" then not_reverse let b7 = "-" goto show_digit2 last_number2: let b6 = 1 show_digit2: poke $C0,b6 'save b6 if b6 = 1 or b6 = 2 then motora if b6 = 4 or b6 = 8 then motorb if b6 = 16 or b6 = 32 then motorc if b6 = 64 or b6 = 128 then motord goto mot_key motora: let b6 = "A" goto show_digit3 motorb: let b6 = "B" goto show_digit3 motorc: let b6 = "C" goto show_digit3 motord: let b6 = "D" show_digit3: writei2c $20,($20,b6,$20,b7) poke $C1,b7 gosub digits peek $C0,b6 'restore b6 peek $C1,b7 'restore b7 goto mot_key not_reverse: let b7 = "+" goto show_digit2 mot_off: pwmout 1,255,0 'pwm1 off pwmout 2,255,0 'pwm2 off goto hdt '------------------------------------------------------------------------' '----------------------| PLACE YOUR PROGRAM HERE |-----------------------' usr: goto disp 'last line in your program '----------------------| PLACE YOUR DEMO HERE |--------------------------' demo: goto disp 'last line in your program '------------------------------------------------------------------------' end '-------------------------| SUBROUTINES |--------------------------------' '---------| DO NOT DELETE OR CHANGE THE SUBROUTINES BELOW |--------------' interrupt: 'check for infrared input pause 10 if pin0 = 1 then no_infra 'check for false ir signal infrain 'get ir value no_infra: setint %00000000,%00000001 'set for infrared input pin return '-------------------------| DISPLAY |-------------------------------------' init_disp: for w0 = b3 to b4 readi2c w0,(b2) 'read from I2C eeprom let pins = b2 if b2 > $21 then com low portc 6 'cd low goto dat com: 'command high portc 6 'cd high dat: 'data low portc 5 'ce low high portc 5 'ce high next w0 return cursor_pos: 'set b3 & $C3 before calling subroutine low portc 6 'cd let pins = b3 low portc 5 'ce high portc 5 'ce peek $C3,b3 'get screen High Address let pins = b3 low portc 5 'ce high portc 5 'ce let pins = $24 'set address pointer high portc 6 'cd low portc 5 'ce high portc 5 'ce let pins = $B0 `$B0 auto increase data write low portc 5 'ce high portc 5 'ce low portc 6 'cd return display: 'set w0, b3 & b4 before calling subroutine gosub cursor_pos 'b4 is the numbers characters to read display2: readi2c w0,(b2) 'w0 is the address in the 32K I2C rom let b2 = b2 - $20 'substract $20 instead of $32 in lcd.s let pins = b2 low portc 5 'ce high portc 5 'ce let w0 = w0 + 1 let b4 = b4 - 1 if b4 <> 0 then display2 cancel_auto: let pins = $B2 `$B2 cancel auto increase data write high portc 6 'cd low portc 5 'ce high portc 5 'ce low portc 6 'cd return display_char: 'one ASCII character - set cursor position first low portc 6 'cd let b2 = b2 - $20 `substract $20 instead of $32 in lcd.s let pins = b2 low portc 5 'ce high portc 5 'ce return 'must end with gosub cancel_auto '---------------------| CONVERT WORD TO 4 BYTES |-------------------------------' digits: low portc 0 'latch let b13 = w4 / 1000 'convert W4 result for let w5 = b13 * 1000 'digital output in let w5 = w4 - w5 'Registers b10 to b13 let b12 = w5 / 100 'b13 is the MSB let w3 = b12 * 100 let w3 = w5 - w3 let b11 = w3 / 10 let b10 = b11 * 10 let b10 = w3 - b10 let b10 = b10 + $30 'convert to ASCII let b11 = b11 + $30 'convert to ASCII if b13 = 0 then make_space let b12 = b12 + $30 'convert to ASCII let b13 = b13 + $30 'convert to ASCII goto show_data make_space: let b13 = $20 if b12 = 0 then make_space2 let b12 = b12 + $30 'convert to ASCII goto show_data make_space2: let b12 = $20 'convert to ASCII space show_data: writei2c $24,(b13,b12,b11,b10) pause 100 let b3 = $57 'set cursor posistion let w0 = $20 'begining of text data let b4 = $08 'display 8 bytes gosub display 'display return '----------------| CONVERT 2 x 4-BIT BCD TO 2 x BCD BYTES |--------------------' get_time: i2cslave %11010000, i2cslow, i2cbyte'set for i2c RTC readi2c 0,(b0,b1,b2) let b10 = b0 & $0F 'AND to get LSBs let b0 = b0 - b10 '\ get MSBs let b10 = b10 + $30 ' \ change to ASCII let b11 = b0 / $0F '----\ change to LSB let b11 = b11 + $30 'change to ASCII let b13 = b1 & $0F 'AND to get LSBs let b1 = b1 - b13 'get MSBs let b13 = b13 + $30 'change to ASCII let b1 = b1 / $0F 'change to LSB let b1 = b1 + $30 'change to ASCII let b7 = b2 & $0F 'AND to get LSBs let b2 = b2 - b7 'get MSBs let b7 = b7 + $30 'change to ASCII let b6 = b2 / $0F 'change to LSB let b6 = b6 + $30 'change to ASCII ' (hours minutes seconds) writei2c $20,(b6,b7,":",b1,b13,":",b11,b10) let b3 = $57 'set cursor posistion let w0 = $20 'begining of text data let b4 = $08 'display 8 bytes gosub display i2cslave %10100000, i2cfast, i2cword'set for i2c eeprom return '----------| READ KEY PAD VOLTAGE OR IR AND CONVERT TO VALUE IN b5 |---------------' key_pad: if infra = 1 then one if infra = 2 then two if infra = 3 then three if infra = 4 then four if infra = 11 then disp 'main screen if infra = 17 then start 'reset readadc 1,b5 if b5 > 180 and b5 < 220 then one '1st key pressed if b5 > 130 and b5 < 170 then two '2nd key pressed if b5 > 80 and b5 < 120 then three '3rd key pressed if b5 > 30 and b5 < 70 then four '4th key pressed goto key_pad one: let b5 = 0 goto finish two: let b5 = 1 goto finish three: let b5 = 2 goto finish four: let b5 = 3 finish: let infra = 0 return '---------------------------------| EEPROM DATA |---------------------------------' ' NOT CURRENTLY USED, ALL TEXT AND GRAPHICS ARE STORED IN THE I2C EEPROM ' | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F | 'data $00,(129,000,000,064,016,000,065,000,000,034,000,000,160,151)'init_screen ' com,dat,dat,com,dat,dat,com,dat,dat,com,dat,dat,com,com ' ( 0123456789ABCDEF ) 'data $10,(" HRD USR DEMO")'1st MAIN 'data $20,("SET HDT IO END")'2nd HRD 'data $30,("SERV MOT SND END")'3rd HDT 'data $40,("DIN CLK ADC END")'3rd IO 'data $50,("SER RMT IR END")'3rd SET 'data $60,(" + SET NEXT END")'4th CLOCK 'data $70,(" + - NEXT END")'4th ADC