Hi, I have dug out some code I used for this chip, but it is PAL, you should be able to change the appropriate bit(s) to NTSC.
It puts the word TEST. on 3rd line at right hand side of the screen.
It also detects synchs and will auto switch mode as necessary, and when there is no incoming video it will display that No Synchs message on screen.
I have modified the code from the original, it had a lot of debug stuff in it, I have not tested since although it should work, (it compiles OK) , I post to let you check the values in the code you have.
I will try and test in the next few days when I get some video stuff resurected.
Just a note it is much easier to put the values in as binary eg %0000000011001100 rather than have to work it out when debugging.
Darrel Taylor ALLDIGITAL.pbp if you do not have it.Code:'**************************************************************** '* Name : STV-SYNCHS RELEASE * '* Author : BOB LEGGETT * '* Notice : Copyright (c) 2009 * '* : All Rights Reserved * '* Date : around 2009 or so rehashed now '17 * '* Version : 1.0 * '* Notes : VIDEO IDENT * '* : * '**************************************************************** ' WORKS USES SYNC FOR SWITCHING BETWEEN MIXED AND FULL TEXT MODE ' GOING FROM VID IN TO TEXT AND BACK TO VID IN @ device PIC16F628A,HS_OSC,BOD_ON,MCLR_ON,PWRT_ON INCLUDE "ALLDIGITAL.pbp" define OSC 4 'TV CHIP CONNECTIONS '--------------------------------------------------------------- '16f628a TVSDA VAR PORTB.1 '0 OUTPUT pin 11 stv CS0 VAR PORTB.0 '0 OUTPUT pin 13 stv TVSCL VAR PORTB.5 '0 OUTPUT pin 12 stv SYNCH0 VAR PORTB.2 '1 'INPUT to pin 7 stvchip HEARTBEAT VAR PORTB.6 'OUTPUT 0 led '--------------------------------------------------------------- ZOOMREG CON %0000000011001100 ' 12 ZOOM REGISTER COLREG CON %0000000011001101 ' 13 COLOUR REGISTER CONREG CON %0000000011001110 ' 14 CONTROL REGISTER POSREG CON %0000000011001111 ' 15 POSITION REGISTER MODEREG CON %0000000011010000 ' 16 MODE REGISTER ICOUNT VAR BYTE BITCOUNTER VAR BYTE WDATA VAR WORD CHARCOUNTER VAR BYTE ' LINECOUNTER VAR BYTE ' STVCHAR VAR BYTE ASCCHAR VAR BYTE CHARS VAR BYTE CHARS2 VAR BYTE TEMP VAR BYTE TEMP1 VAR BYTE COUNTER VAR BYTE PULSES VAR BYTE CURRENTMODE0 VAR BYTE '---------------------------------------------------------------- ' TOPLEFT CON 0 ' TOPMIDDLE CON 5 ' TOPRIGHT CON 10 ' BOTLEFT CON 2560 '10*256 ' BOTMIDDLE CON 2565 '(10*256)+ 5 ' BOTRIGHT CON 2570 '(10*256)+ 10 '---------------------------------------------------------------- DATA @0,"TEST.",$FF,"NO SYNCHS RECEIVED",$FF '---------------------------------------------------------------- '628 TRISB=%10011100 '---------------------------------------------------------------- PAUSE 500 HIGH HEARTBEAT GOSUB Init PAUSE 500 GOSUB Init CURRENTMODE0=255 ' FORCES TRYSYNCHS TO SET MODE FIRST TIME Demo: CHARCOUNTER = 0 LINECOUNTER = 0 ' CURRENTMODE0 = 0 '0 = MIXED 1 = TEXT gosub CLS GOSUB TRYSYNCHS '================================== TEMP = 0 LOOPER: GOSUB HEADER ' LINE 3 RIGHT HAND SIDE TEST. IF CURRENTMODE0=1 THEN GOSUB NOVIDEO ' DISPLAYS NO VIDEO IF NO INCOMING SYNCHS ENDIF GOSUB TRYSYNCHS '=========================== PAUSE 500 'I/2 SECOND DELAY TOGGLE HEARTBEAT ' LED GOTO LOOPER 'DO IT FOREVER DISPLAYCHAR: WDATA = %0001011100000000 + STVCHAR GOSUB SEND RETURN SETLINE: WDATA = LINECOUNTER*256 + CHARCOUNTER GOSUB Send 'position cursor RETURN WasteTime: ' WORKS WITH LESS NOPS pauseus 20 ' was 20 nops RETURN StartCommunication: TVSCL = 1 'HIGH TVSCL GOSUB WasteTime CS0 = 0 'LOW CS0 GOSUB WasteTime TVSCL = 0 'LOW TVSCL GOSUB WasteTime RETURN StopCommunication: TVSCL = 1 'HIGH TVSCL GOSUB WasteTime CS0 = 1 'HIGH CS0 GOSUB WasteTime RETURN SendOne: TVSDA = 1 'HIGH TVSDA GOSUB WasteTime TVSCL = 0 'LOW TVSCL GOSUB WasteTime TVSCL = 1 'HIGH TVSCL GOSUB WasteTime RETURN SendZero: TVSDA = 0 'LOW TVSDA GOSUB WasteTime TVSCL = 0 ' LOW TVSCL GOSUB WasteTime TVSCL = 1 'HIGH TVSCL GOSUB WasteTime TVSDA = 1 'HIGH TVSDA GOSUB WasteTime RETURN OutByte: FOR BITCOUNTER = 1 TO 16 IF WDATA.15 = 1 THEN GOSUB SendOne ELSE GOSUB SendZero ENDIF WDATA = WDATA << 1 NEXT BITCOUNTER RETURN Send: GOSUB StartCommunication GOSUB OutByte GOSUB StopCommunication RETURN '------------------------------------------------------------- Init: ' PAUSE 50 added - seems to improve reliability of init TVSCL = 1 'HIGH TVSCL TVSDA = 1 'HIGH TVSDA CS0 = 1 'HIGH CS0 WDATA = $3000 '%110000 00000000 GOSUB Send ' Init STV5730 PAUSE 50 WDATA = $3000 GOSUB Send PAUSE 50 WDATA = $00DB '%00000000 11011011 GOSUB Send PAUSE 50 WDATA = $1000 '%00010000 00000000 GOSUB Send PAUSE 50 '------------------------------------------------------------- WDATA = %0000000011001100 GOSUB Send ' Init registers (point to register 12) PAUSE 50 '------------------------------------------------------------- WDATA = %0001000000000000 'NORMAL ' WDATA = %0001000011110000 '4 PIXELS HORIZ AND VERT GOSUB Send ' Zoom ADDRESS 12 PAUSE 50 '------------------------------------------------------------- WDATA = %0001001000000000 ' WDATA = %0001001000000100 GOSUB Send ' Color ADDRESS 13 PAUSE 50 '-------------------------------------------------------- WDATA= %0001101111010100 'CHANGE BIT 0 TO 1 FOR TEXT ONLY GOSUB Send ' Control ADDRESS 14 '------------------------------------------------------------- WDATA = %0001011111001111 GOSUB Send ' Position ADDRESS 15 '------------------------------------------------------------- WDATA = %0001000100101110 '$183E BIT 11 CHANGED TO 0 M4 = 0 GOSUB Send ' Mode ADDRESS 16 %0001100000111110 '------------------------------------------------------------- WDATA = $00C0 '%00000000 11000000 GOSUB Send ' Set row attributes FOR ICOUNT = 0 TO 10 WDATA = $10C4 '%00010000 11000100 ' WDATA =%0001000010000111 GOSUB Send NEXT ICOUNT RETURN CLS: 'character=$0B 'SPACE TEMP1=0 ' LINECOUNTER TEMP =0 'CHARCOUNTER loop2: WDATA = 0 ' LINECOUNTER*256 + CHARCOUNTER ADDRESS GOSUB Send LOOP3: ' :CHARACTERS WDATA = %0001011100001011 ' 1011 0BH SPACECHARACTER GOSUB Send TEMP = TEMP + 1 IF TEMP >= 28 THEN TEMP = 0 TEMP1=TEMP1 + 1 ENDIF IF TEMP1 >= 11 THEN SCREENBLANK GOTO LOOP3 SCREENBLANK: RETURN GETSTVCHAR: 'CONVERT ASCII TO STV STVCHAR =$7F ' FORCES CLOCK PICTURE IF ERROR LOOKDOWN ASCCHAR,["0123456789- ABCDEFGHIJKLMNOPQRSTUVWXYZ:./'abcdefghijklmnopqrstuvwxyz"],STVCHAR RETURN HEADER: LINECOUNTER=2 'SET START POSITION CHARCOUNTER=23 'SET CURSOR POSITION GOSUB SETLINE FOR CHARS2=0 TO 4 READ CHARS2, ASCCHAR gosub GETSTVCHAR 'CONVERT ASCII TO STV GOSUB DISPLAYCHAR NEXT RETURN NOVIDEO: LINECOUNTER=5 'SET START POSITION CHARCOUNTER=4 'SET CURSOR POSITION GOSUB SETLINE FOR CHARS2=6 TO 23 ' FROM EEPROM DATA READ CHARS2, ASCCHAR gosub GETSTVCHAR 'CONVERT ASCII TO STV GOSUB DISPLAYCHAR NEXT RETURN TRYSYNCHS: PULSES=0 COUNT SYNCH0,4,PULSES '3MS SHOULD COUNT TO 2 OR 3 IF PULSES > 0 THEN MIXED0 FULL0: IF CURRENTMODE0=1 THEN RETURN WDATA= %0000000011001110 'CONTROL REGISTER GOSUB SEND WDATA= %0001101111010101 'CHANGE BIT 0 TO 1 FOR TEXT ONLY OTIGINAL ' WDATA= %0001101111010100 'CHANGE BIT 0 TO 1 FOR TEXT ONLY GOSUB SEND STAYHERE02: CURRENTMODE0=1 GOSUB CLS GOBACK0: RETURN MIXED0: IF CURRENTMODE0=0 THEN RETURN WDATA= %0000000011001110 'CONTROL REGISTER GOSUB SEND WDATA= %0001101111010100 GOSUB SEND STAYHERE01: CURRENTMODE0=0 GOSUB CLS RETURN
Code:;*************************************************************************** ;* Name : ALLDIGITAL.pbp * ;* Author : Darrel Taylor * ;* Notice : Copyright (c) 2009 * ;* : All Rights Reserved until Abused * ;* Date : 4/30/2009 * ;* Version : 1.5 (3/7/2011) * ;* Notes : An INCLUDE file that will automatically enable * ;* : all DIGITAL Inputs multiplexed with the ADC or Comparators * ;* : Works with ANY PIC, using either PM or MPASM * ;*************************************************************************** ;* Useage : INCLUDE "AllDigital.pbp" * ;* : yup, that's it. Just include the file and it's All Digital * ;* : Adding this line to your program will display the values * ;* : used to achieve AllDigital ... (if using MPASM) * ;* : DEFINE SHOWDIGITAL 1 * ;*************************************************************************** ;* Versions: 1.0 - Initial release * ;* 5/6/2009 : 1.1 - Added Shared address SFR support for 18F87J50 family * ;* : Thanks to mister_e * ;* 5/9/2009 : 1.2 - Removed MPASM specific opcode (variable), for PM.exe * ;* : Thanks to Tobias * ;* 7/11/2009: 1.3 - Added ANSELA,ANSELB,ANSELD,ANSELE for the 16F72x series* ;* 7/19/2010: 1.4 - Added ANSEL0 and ANSEL1 for the 18F4431 series. * ;* 3/7/2011: 1.5 - Update for latest chips from Microchip * ;*************************************************************************** ;Check 18F45k80 ---- ; Uses ANCONx with ANSEL0 and ANSEL1 as bit names ; other PIC's have ANSEL0 and ANSEL1 ASM ;----[Module defaults]------------------------------------------------------ #define SHOWDIGITALDEFAULT 0 ifdef SHOWDIGITAL SHOWDIGITALRESULT = SHOWDIGITAL else SHOWDIGITALRESULT = SHOWDIGITALDEFAULT endif ifndef PM_USED ifndef ADLISTALL nolist endif endif ;----[Attempt to Set a registers Value]------------------------------------- SetReg macro RegOut, Cin ifndef PM_USED ifndef ADLISTALL nolist endif endif ifdef RegOut ifndef PM_USED list endif MOVE?CB Cin, RegOut if (SHOWDIGITALRESULT == 1) ifndef PM_USED messg RegOut = Cin endif endif ifndef PM_USED ifndef ADLISTALL nolist endif endif endif endm ;----[A/D Converter registers]---------------------------------------------- HasANSEL = 0 ifdef ANSEL HasANSEL = 1 SetReg ANSEL , 0 ; if chip has ANSEL's, clear them endif ifdef ANSEL0 ifndef ANCON0 HasANSEL = 1 SetReg ANSEL0, 0 endif endif ifdef ANSEL1 ifndef ANCON0 HasANSEL = 1 SetReg ANSEL1, 0 endif endif ifdef ANSELA HasANSEL = 1 SetReg ANSELA, 0 endif ifdef ANSELB HasANSEL = 1 SetReg ANSELB, 0 endif ifdef ANSELC HasANSEL = 1 SetReg ANSELC, 0 endif ifdef ANSELD HasANSEL = 1 SetReg ANSELD, 0 endif ifdef ANSELE HasANSEL = 1 SetReg ANSELE, 0 endif ifdef ANSELF HasANSEL = 1 SetReg ANSELF, 0 endif ifdef ANSELG HasANSEL = 1 SetReg ANSELG, 0 endif ifdef ANSELH HasANSEL = 1 SetReg ANSELH, 0 endif ifdef ANSELI HasANSEL = 1 SetReg ANSELI, 0 endif ifdef ANSELJ HasANSEL = 1 SetReg ANSELJ, 0 endif ifdef ANSELK HasANSEL = 1 SetReg ANSELK, 0 endif if (HasANSEL == 0) ifdef ANCON0 ; Several chips use ANCON0 and ANCON1 ifdef ADSHR ; if chip has shared address SFR's MOVE?CT 1, WDTCON,ADSHR ; switch to shared address registers if (SHOWDIGITALRESULT == 1) messg WDTCON.4 = 1 endif endif SetReg ANCON0, 0xFF ; ifdef PCFG15 ; 0 = Analog with these bits SetReg ANCON1, 0xFF else SetReg ANCON1, 0x7F endif ifdef ADSHR ; if chip has shared address SFR's MOVE?CT 0, WDTCON,ADSHR ; put SFR's back to legacy if (SHOWDIGITALRESULT == 1) messg WDTCON.4 = 0 endif endif else ifdef PCFG6 ; Some chips use ADCON1 bits SetReg ADCON1, 0x7F ; the same way as ANCONx else ifdef PCFG3 ; if there's a PCFG3 bit ifdef ADCON2 ; but has no ADCON2, more than 8 A/D's SetReg ADCON1, 0x0F ; A/D cfg from table = 0x0F else SetReg ADCON1, 7 ; most common, 8 or less A/D ch's endif else ifdef PCFG2 ifdef ADCON1 SetReg ADCON1, 7 ; A/D is 8-bit, 5 ch's endif else ifdef ADCON0 ; if there's an ADCON0 ifndef ADCON1 ; but not an ADCON1 SetReg ADCON0, 0 ; A/D is 8-bit and ADS bits are in ADCON0 endif endif endif endif endif endif endif ;----[Comparators]---------------------------------------------------------- ifdef CMCON ifdef CMEN0 ; 18F1230/1330 ;SetReg CMCON, 0 ; default already else ifdef CM2 SetReg CMCON, 7 else ifdef PM_USED "ALLDIGITAL: CMCON value not found" else messg "ALLDIGITAL: CMCON value not found" endif endif endif endif ifdef CMCON0 ifdef NOT_COUTEN SetReg CMCON0, 0xF1 ; 10F204/206 else ifdef CMCH SetReg CMCON0, 0 ; 12F609/615 else ifdef CM2 SetReg CMCON0, 7 ; 12F635/683, else ; 16F636/639/684/688/913/914/916/917/946 ifndef PM_USED "ALLDIGITAL: CMCON0 value not found" else messg "ALLDIGITAL: CMCON0 value not found" endif endif endif endif endif ifdef CM1CON0 ; individual comparator controls ifdef NOT_C1OUTEN SetReg CM1CON0, 0xF1 ; 12F510/506, 16F526 else ; SetReg CM1CON0, 0 ; these already default to 0 -------------- endif ; 16F882/883/884/886/887/ 610/616 endif ; 16F631/677/685/687/689/690 ; these aren't 0, but default to OFF ; 18F24J11/25J11/26J11/44J11/45J11/46J11 ; 18F24J50/25J50/26J50/44J50/45J50/46J50 ifdef CM2CON0 ifdef NOT_C2OUTEN SetReg CM2CON0, 0xF1 else ; SetReg CM2CON0, 0 ; already default to 0 -----see above- endif endif ; CM1CON ; these aren't 0, but default to OFF ; 18F65J50/66J50/66J55/67J50/66J11/66J16/67J11 ; CM2CON ; 18F85J50/86J50/86J55/87J50/86J11/86J16/87J11 ifndef PM_USED list endif ENDASM




Bookmarks