I'll have to explain some things about the program. The project is a text-based video game system designed around multiple slave PICs and a master PIC, which communicates between both the console slave chips and game cartridge master/slave chips. The first chip to send serial data to the consoles master chip, is the console title chip. The data is then sent from the console master chip to a product called the Tellymate, which converts serial data to composite video based on hexadecimal characters from code page 437.
Links:
Tellymate - http://www.batsocks.co.uk/products/O...0TTL%20Kit.htm
Code Page 437 - http://en.wikipedia.org/wiki/Code_page_437
Like I said before, when this program is on the 16f887, it works flawlessly.
Code:'Define device 16F887 'Define OSC 8 'ANSEL=0 ' A/D disabled for ANS0 to ANS7 'ANSELH=0 ' A/D disabled for ANS8 to ANS13 'CM1CON0 = 0 ' Disable comparators 'CM2CON0 = 0 ' These default to disabled at POR, but just in case 'CM2CON1 = 0 'ADCON1 = 7 'IOCB = 0 'INTCON = 0 define device 18f4685 @ __CONFIG _CONFIG1H, _OSC_IRCIO67_1H & _FCMEN_OFF_1H & _IESO_OFF_1H @ __CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H @ __CONFIG _CONFIG3H, _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_ON_3H @ __CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _BBSIZ_1024_4L & _XINST_OFF_4L OSCTUNE = %00000000 OSCCON = %01110000 define OSC 8 CMCON = 0 ADCON0 = 7 ADCON1 = 7 ADRESH = %00000000 ADRESL = %00000000 INTCON = 0 INTCON2 = 0 INTCON3 = 0 IPR1 = 0 PIR1 = 0 PIE1 = 0 DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0 DEFINE HSER_CLROERR 1 ' Clear overflow automatically DEFINE HSER_SPBRG 51 ' 9600 Baud @ 8MHz, 0.16% SPBRGH = 0 BAUDCON.3 = 1 ' Enable 16 bit baudrate generator 'DEFINE HSER_RCSTA 90h ' Enable Serial PORT 'DEFINE HSER_TXSTA 24h ' Enable transmit 'DEFINE HSER_SPBRG 129 ' set USART to 9600 baud (when BRGH=1) 'DEFINE HSER_CLROERR 1 ' Enable automatic overrun error ''DEFINE LOADER_USED 1 '~~~~~Variables~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ '~~~~~Slave Chip~~~~~ Cart_Audio var portc.0 'Switch 1AB Cart_Title var portc.1 'Switch 1CD Audio var portc.2 'Switch 2AB Keyboard var portc.3 'Switch 2CD TellyMate var portd.0 'Switch 3AB Slaves var portd.1 'Switch 3CD Title var portd.2 'Switch 4AB Cart_Master var portd.3 'Switch 4CD CNT var byte CNT2 var byte SerDat var byte MasterTrig var portd.4 'chip sensor pin MasterCheck var bit Master_Busy var porte.0 'timing pin AudioTrig var portd.5 'chip sensor pin TitleTrig var portd.6 'chip sensor pin Assign_Var var byte Key_Var var byte Letter_CNT var byte B1 var byte B2 var byte B3 var byte B4 var byte B5 var byte B6 var byte B7 var byte B8 var byte B9 var byte B10 var byte B11 var byte B12 var byte B13 var byte B14 var byte B15 var byte B16 var byte B17 var byte B18 var byte B19 var byte B20 var byte B21 var byte B22 var byte B23 var byte B24 var byte B25 var byte '~~~~~Initialize TextBox~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ trisc.0 = 0 trisc.1 = 0 'make all SLAVE pins OUTPUTS trisc.2 = 0 trisc.3 = 0 trisd.0 = 0 trisd.1 = 0 trisd.2 = 0 trisd.3 = 0 trisd.4 = 1 'make Master_Trigger INPUT trisd.5 = 1 'make Audio_Trigger INPUT trisd.6 = 1 'make Title_Trigger INPUT trise.0 = 1 'make Master_Busy INPUT cart_audio = 0 Cart_title = 0 Audio = 0 'ALL Slaves set to keyboard = 0 'no communication tellymate = 0 'Motherchip to Tellymate Slaves = 0 'Slave chips to Motherchip title = 0 cart_master = 0 pause 30 '~~~~~AutoBaud~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ AutoBaud: tellymate = 1 pause 30 'mandatory 30ms pause for 4066 switching hserout ["U", $1B, $45] 'transmit autobauding character, clear screen and return home hserout [$1B, $76] 'allow text to continue on next line 'hserout [$1B, $66] 'CURSOR OFF pause 500 tellymate = 0 pause 30 mastercheck = 0 cnt = 0 '~~~~~Program Start~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Start: audio = 0 cart_audio = 1 GOTO LOAD_CARTRIDGE slaves = 1 'allow slave communications audio = 1 'enable audio communications pause 30 hserout [0] 'play Intro sound file pause 50 audio = 0 'disable audio communications pause 30 title = 1 'enable TITLE SCREEN communications tellymate = 1 pause 30 repeat hserin [serdat] 'display TEXTBOX TITLE SCREEN hserout [serdat] until serdat = $BC 'last command sent by CARTRIDGE TITLE pause 10 'allow SerDat to display everything title = 0 'disable TITLE SCREEN communications tellymate = 0 'pause 30 pause 1700 'Main: 'keyboard = 1 'enable typing 'pause 30 'hserin [serdat] 'receive keyboard data 'if serdat = $0D then 'IF RETURN has been pressed ' slaves = 0 'disable slave communications ' keyboard = 0 'disable typing ' pause 30 'and access boot menu ' hserout [$1B, $45] 'clear screen and cursor to 0,0 ' goto cartridge_check 'else ' goto main 'repeat until RETURN is pressed 'endif '~~~~~Cartridge Check~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Cartridge_Check: tellymate = 1 'enable Motherchip to TellyMate communications pause 30 hserout [$1B, $45] HSEROUT [$1B, $65] 'CURSOR ON gosub next_line hserout ["Checking Cartridge Port.", $0D, $0A, "Do Not Add/Remove Cartridge/"] if mastertrig = 1 then 'IF portd.4 = 1, THEN mastercheck = 1 'cartridge is there else mastercheck = 0 'cartridge is missing endif gosub loading_dots gosub next_line gosub next_line 'if cartridge is there and hasn't been removed~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if mastertrig = 1 and mastercheck = 1 then gosub next_line hserout ["Cartridge Found.", $0D, $0A, "Loading Cartridge Data/"] Gosub Loading_dots gosub next_line gosub next_line pause 200 hserout [$1B, $66] 'CURCOR OFF hserout [$20, $F9, "Master Chip Located/", $0D, $0A] pause 15 if audiotrig = 1 then hserout [$20, $F9, "Audio Chip Located/", $0D, $0A] endif pause 15 if titletrig = 1 then hserout [$20, $F9, "Title Chip Located/", $0D, $0A] endif pause 15 gosub next_line gosub next_line hserout [$1B, $59, 50, 34, $AF, $AF, "Press Return To Load Cartridge", $AE, $AE] pause 10 tellymate = 0 pause 30 Cart_Loop: slaves = 1 keyboard = 1 serdat = 0 repeat hserin [serdat] until serdat != 0 if serdat = $0D then slaves = 0 keyboard = 0 goto load_cartridge else goto cart_loop endif endif 'if cartridge is missing and hasn't been added~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if mastertrig = 0 and mastercheck = 0 then gosub next_line hserout ["No Cartridge Was Found.", $0D, $0A, "Loading Text Editor/"] gosub loading_dots gosub next_line gosub next_line hserout [$1B, $66, $1B, $45] gosub next_line pause 100 hserout [$1B, $59, 33, 44, $AF, $AF, "Text Editor", $AE, $AE] gosub next_line gosub next_line hserout [$1B, $65] gosub text_editor endif 'if cartridge was removed while loading~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if mastertrig = 1 and mastercheck = 0 then gosub cart_error endif 'if cartridge was inserted while loading~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if mastertrig = 0 and mastercheck = 1 then gosub cart_error endif '~~~~~Text Editor~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Text_Editor: slaves = 1 'allow slave communications keyboard = 1 'enable typing pause 30 Text_Editor_Loop: hserin [serdat] 'receive data from Keyboard hserout [serdat] 'then display it goto text_editor_loop '~~~~~Subroutines~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Cart_Error: slaves = 1 audio = 1 pause 30 hserout [2] pause 50 audio = 0 pause 30 hserout ["Error/"] slaves = 0 audio = 0 pause 500 'reset to Cartridge_Check gosub next_line gosub next_line return Loading_Dots: pause 500 hserout ["."] pause 500 hserout ["."] 'just some dots pause 500 hserout ["."] pause 1000 return Next_Line: hserout [$0D, $0A] 'jump to column 0 of next row return '~~~~~Load Cartridge~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Load_Cartridge: slaves = 1 'allow slave communications if audiotrig = 1 then 'if AUDIO chip is in CARTRIDGE cart_audio = 1 'enable audio communications pause 30 hserout [1] 'play Intro Cartridge sound file pause 50 cart_audio = 0 'disable audio communications pause 30 endif if titletrig = 1 then 'if TITLE chip is in CARTRIDGE tellymate = 1 cart_title = 1 'show title pause 30 endif 'pause 30 Load_Cartridge_Loop: repeat hserin [serdat] 'receive data from Cartridge hserout [serdat] 'then display it until serdat = $BC 'last character of Cartridge Title Screen pause 30 cart_title = 0 cart_audio = 0 pause 5000 hserout [$1B, $45] 'clear screen and cursor to 0,0 pause 30 'goto menu '~~~~~Menu~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Menu: 'tellymate = 1 cart_master = 0 'close master_chip communications while master_busy = 1 'wait until master chip is finished working 'hserout ["."] goto menu 'repeat until master_chip is done wend tellymate = 0 'disable text on screen serdat = 0 'unassigned value for Menu loop slaves = 1 'enable slave communications cart_master = 1 'enable master_chip communications repeat hserin [serdat] 'receive subroutine number to execute until serdat != 0 'wait to receive command select case serdat 'read subroutine number case $31 '1 goto Master_screen_loop 'if serdat = 1 case $32 '2 goto no_text_keyboard 'if serdat = 2 case $33 '3 goto keyboard_loop 'if serdat = 3 end select goto menu '~~~~~Master_Screen_Loop~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Master_Screen_Loop: 'display first/next screen of game 'hserout [$1B, $45] 'clear text from current screen tellymate = 1 'enable text on screen cart_master = 1 'enable master_chip communications repeat hserin [serdat] 'receive screen character from game hserout [serdat] 'and display it on screen until serdat = $00 'until terminate command is sent tellymate = 0 goto menu '~~~~~No_Text_Keyboard~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ No_Text_Keyboard: 'keyboard/cartridge transactions tellymate = 0 'without text on screen goto key_assignment Key_Assignment: cnt2 = 0 'assigned letter count variable Letter_CNT = 0 'assigned letter quantity serdat = 0 '~~~~~Receive Letter_CNT character amount~~~~~ slaves = 1 'enable slave communications cart_master = 1 'enable Cart_Master communications repeat hserin [letter_cnt] 'receive letter amount pauseus 14 ' tellymate = 1 ' hserout ["Letter_CNT = ", dec letter_cnt] 'display letter amount until letter_cnt >= 1 and letter_cnt <= 25 '~~~~~Receive Corresponding Characters~~~~~ 'slaves = 1 'enable slave communications 'cart_master = 1 'enable Cart_Master communications cnt2 = 0 'pause 30 repeat hserin [serdat] 'receive letter variable pauseus 14 ' tellymate = 1 ' hserout [serdat] write cnt2, serdat 'and store in EEPROM 0-24 cnt2 = cnt2 + 1 until cnt2 = letter_cnt 'until CNT2 equals letter amount cart_master = 0 pause 30 cnt2 = 0 'reset CNT2 value '~~~~~Keyboard_Loop~~~~~~~~~~~~~~~~~~~~~~~~ Keyboard_Loop: 'tellymate = 0 'slaves = 1 'enable slave communications serdat = 0 'reset SerDat value repeat 'repeat cart_master = 0 'disabling cart_master communications keyboard = 1 'enabling keyboard communications hserin [serdat] 'and receiving data from the keyboard until serdat != 0 'then keyboard = 0 'disabling keyboard communications cart_master = 1 'enabling cart_master communications hserout [serdat] 'and sending keyboard data to cartridge repeat read cnt2, key_var 'save CNT2 value (EEPROM location) to Key_Var select case serdat 'and compare Key_Var to keyboard input ' case $0D 'if keyboard = ENTER ' goto menu case key_var 'if keyboard = requested character goto menu ' case else 'if keyboard = anything else ' cnt2 = cnt2 + 1 'add 1 to CNT2 ' goto keyboard_loop end select cnt2 = cnt2 + 1 until cnt2 >= letter_cnt 'until all requested letters cnt2 = 0 'have been scanned goto keyboard_loop '~~~~~Yes_Text_Keyboard~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Yes_Text_Keyboard: 'keyboard/cartridge transactions 'with text on screen tellymate = 1 goto key_assignment
And here is the data sent from the Title chip, which is a 16f688.
Code:Define device 16F688 Define OSC 8 ANSEL=0 ' A/D disabled for ANS0 to ANS7 'ANSELH=0 ' A/D disabled for ANS8 to ANS13 'CM1CON0 = 0 ' Disable comparators 'CM2CON0 = 0 ' These default to disabled at POR, but just in case 'CM2CON1 = 0 CMCON0 = 0 ADCON1 = 7 'IOCB = 0 'INTCON = 0 DEFINE HSER_RCSTA 90h ' Enable Serial PORT DEFINE HSER_TXSTA 24h ' Enable transmit DEFINE HSER_SPBRG 129 ' set USART to 9600 baud (when BRGH=1) DEFINE HSER_CLROERR 1 ' Enable automatic overrun error DEFINE LOADER_USED 1 '~~~~~Variables~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~` SerDat var byte Trigger var portc.3 trisc.3 = 1 '~~~~~Start-up Screen~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Main: if trigger = 1 then pause 100 if trigger = 1 then 'Use command "$1B, $59 to place cursor, and 'add (cursor location +32) for command coordinates HSEROUT [$1B, $66] 'CURSOR OFF '1 5 10 15 20 25 30 35 38 hserout [$C9, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $BB] HSEROUT [$BA, $DE, $DC, " ", " ", $DB, $DC, " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", $DC, $DC, " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", $BA] HSEROUT [$BA, " ", $DB, $DB, $DB, $DB, $DB, $DB, $DC, $DC, " ", " ", " ", " ", " ", " ", " ", " ", $DC, " ", " ", $DB, $DF, $DF, $DD, " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", $BA] HSEROUT [$BA, " ", " ", " ", " ", $DB, $DD, " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", $DB, " ", " ",$DE, " ", " ", $DE, " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", $BA] HSEROUT [$BA, " ", " ", " ", $DE, $DB, " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", $DE, $DF, $DB, $DF, $DD, $DE, $DB, $DB, $DD, " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", $BA] HSEROUT [$BA, " ", " ", " ", $DB, $DD, " ", $DC, $DC, $DC, " ", $DE, " ", " ", " ", $DC, " ", " ", $DB, " ", " ", $DE, " ", " ",$DE, " ", $DE, $DC, $DC, $DC, " ", $DE, " ", " ", " ", $DC, " ", $BA] HSEROUT [$BA, " ", $DD, $DE, $DB, " ", $DE, " ", " ", " ", $DD, " ", $DF, $DC, $DF, " ", " ", " ", $DB, " ", " ", $DE, " ", " ", " ", $DD, $DE, " ", " ", $DD, " ", " ", $DF, $DC, $DF, " ", " ", $BA] HSEROUT [$BA, $DE, $DD, $DB, $DD, " ", $DB, $DF, $DF, $DF, " ", " ", $DC, $DF, $DC, " ", $DE, $DE, $DD, " ", " ", $DB, " ", " ", " ", $DD, $DD, " ", " ", $DE, " ", " ", $DC, $DF, $DC, " ", " ", $BA] HSEROUT [$BA, " ", $DF, $DF, " ", " ", " ", $DF, $DF, $DF, " ", $DF, " ", " ", " ", $DF, " ", $DF, " ", " ", $DF, $DF, $DF, $DF, $DF, " ", $DF, $DF, $DF, $DF, " ", $DF, " ", " ", " ", $DF, " ", $BA] HSEROUT [$CC, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $B9] HSEROUT [$CC, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $B9] HSEROUT [$BA, " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", $BA] hserout [$BA, "P", "o", "w", "e", "r", "e", "d", " ", "B", "y", ":", " ", " ", $DC, $DC, $DC, " ", " ", " ", " ", " ", " ", $DE, " ", $DE, " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", $BA] HSEROUT [$BA, " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", $DB, " ", $DC, " ", " ", " ", " ", " ", $DE, $DD, $DB, " ", $DC, " ", " ", $DC, " ", " ", $DC, " ", " ", " ", $BA] HSEROUT [$BA, " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", $DB, $DE, $DC, $DD, $DD, $DD, $DD, $DD, $DE, $DE, $DE, $DE, $DC, $DD, $DF, $DB, $DF, $DE, $DC, $DD, " ", " ", $BA] HSEROUT [$BA, " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", $DB, $DE, $DC, " ", $DD, $DD, $DE, " ", $DE, " ", $DE, $DE, " ", $DD, " ", $DB, " ", $DE, $DC, " ", " ", " ", $BA] HSEROUT [$BA, " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "T", "M", $BA] HSEROUT [$BA, " ", " ", "A Product of www.Batsocks.co.uk", " ", " ", " ", $BA] hserout [$CC, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $B9] HSEROUT [$BA, " ", "Circuit Design and Programming By:", " ", $BA] hserout [$ba, " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", $BA] hserout [$BA, " ", " ", " ", " ", " ", " ", "Robby Hannan, March 2012", " ", " ", " ", " ", " ", " ", $BA] HSEROUT [$BA, " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", $BA] HSEROUT [$C8, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $BC] hserout [$00] goto main else goto main endif 'Change line 75 PAUSE time to length of picture scroll + music endif goto main end
Bookmarks