; MM53200 coder emulation with a PIC12C508 ; Origine : Patrick Gueulle, Electronic Design - August 7, 2000 ; Modifié par DA nov 2001 pour accepter 2 bits variables, ; et envoyer 2 codes compléments si demandé ; ; une transmission démarre par ; un start bit ___________|¨¨¨¨|_ ; puis 12 bits de données (Key1 MSB en premier) ; bit à 0 ¨|_____|¨¨¨¨¨¨¨¨|_ pin a la masse sur MM53200 ; ; bit à 1 ¨|_________|¨¨¨¨|_ pin ouverte sur MM53200 ; ; sequence globale : ; 16 fois { start,key1 (8 bits),1,0,b1,b0 pause } ; si(pin S2=0) ; 16 fois { start,key1 (8 bits),0,1,b1,b0 pause } ; puis stop ; si (pin S2=1) on boucle sur la première clé, comme un 53200/3750 ; ;VALIDATION----------------------------------------------------------------- ; mesuré sous simulateur ; Tbità1 = 431 us [@ 4MHz) Tbità0 = 869 us ; vérifié sur MM53200 et UM3750 avec 100k et 270 pF ; avec key0=0xDA = B'1101 1010' et key1=0xA0 = '1011xxxx' ; ; codage 1 2 3 4 5 6 7 8 9 10 11 12 ; open open masse open open masse open masse open masse open open ; list p=12c508 b=12 f=INHX8M include __CONFIG _CP_OFF & _WDT_OFF & _MCLRE_OFF & _IntRC_OSC __IDLOCS h'DADA' ;----- constants --------------------------------------- bit0 equ 0 ; GP0 IO TTL bit 0 of emitted code bit1 equ 1 ; GP1 IO TTL bit 1 of emitted code TX equ 2 ; GP2 IO ST TX driver pin bit3 equ 3 ; GP3 I TTL bit 3 of emitted code !!!!!!!!!! not used nLED equ 4 ; GP4 IO TTL LED cathode (clear bit to light the LED) ; peut servir de trigger S2 equ 5 ; GP5 IO TTL send twice input (put to GND to send complement) Key0 equ 0xDA ; key (8 bits) NbTrans equ 0x10 ; nombre de transmissions dans une séquence ;----- Local data registers --------------------------- TransCount equ 0x07 BitCount equ 0x08 DelayCount equ 0x09 Key1 equ 0x0A Digit0 equ 0x10 Digit1 equ 0x11 ;#define MPSIM 1 org 0 movfw OSCCAL ; store OSCAL value goto begin ; org 0x040 ; skip the first 64 locations not protected by code protect begin movlw 0x80 ; Enable weak pull-up on GP0 and GP1 and GP3 option ; 10000000 movlw 0x2B ; Set GP2,GP4 as outputs and the rest are inputs tris GPIO ; xxIOIOII bcf GPIO,TX ; clear TX drive bsf GPIO,nLED ; LED off movlw 0x80 ; initialize nibble to be sent after key 10xx0000 btfsc GPIO,bit0 ; get bit0 iorlw 0x10 ; put it on position 4 btfsc GPIO,bit1 ; get bit1 iorlw 0x20 ; put it on position 5 movwf Key1 Send1 movlw NbTrans movwf TransCount ; N transmissions NextKey1 call sendkey decfsz TransCount,F goto NextKey1 btfsc GPIO,S2 ; test bit S2 goto Send1 ; c'est fini si S2=1 movf Key1,0 ; inverse les 2 bits de poids forts de KEY1 xorlw b'11000000' movwf Key1 movlw NbTrans movwf TransCount ; N transmissions NextKey2 call sendkey decfsz TransCount,F goto NextKey2 stop goto stop ; et voila c'est fini.... ;---------------------------------------------------------------------------- ; envoie start bit, 12 bits et fait une pause ; durée totale ~1+12x3+24 = 61 slots ; sendkey movlw Key0 movwf Digit0 movf Key1,0 movwf Digit1 movlw 0x0C movwf BitCount ; 12 bits to send bcf GPIO,nLED ; LED on bsf GPIO,TX ; produce start bit call Wait1Slot bcf GPIO,TX NextBit call Wait1Slot bcf STATUS,C ; clear carry rlf Digit1,F ; shift key MSB out first rlf Digit0,F btfss STATUS,C ;if carry is low bsf GPIO,TX ;then send 2 bits at one call Wait1Slot bsf GPIO,TX call Wait1Slot bcf GPIO,TX decfsz BitCount,F ;last bit is not reached goto NextBit bsf GPIO,nLED ; LED off movlw 0x24 ; delai entre 2 émissions = 36 slots movwf BitCount pause call Wait1Slot ; wait 1 slot decfsz BitCount,F goto pause retlw 0 ;---------------------------------------------------------------------------- ; wait 1 slot ; un bit 53200/3750 est fait de 3 slots ; un slot de 53200 dure 32/Fosc, Fosc=2/RC, ; la data sheet 53200 donne une durée bit de 960 us pour 100 kHz ; ici on choisit une fréquence de l'ordre de 74 kHz avec 100 k et 270 pF, durée slot = 432 us Wait1Slot IFDEF MPSIM movlw 1 ELSE movlw 0x55 ; delay 1+1+85*5-1+2+2=430 us ENDIF ;---------------------------------------------------------------------------- ;Delay for 1+W*5-1+2 us with 4MHz oscillator ; maximum for W=0 is 1284 us Delay movwf DelayCount DelayStart: nop nop decfsz DelayCount,F goto DelayStart retlw 0 end