I need to replace the 12C508A in a device. I need more memory since PBP isn't as efficient as ASM. The original 12C508A is a wide SOIC-8 and I can only get 12C509A or 12F509 with that footprint.
My code for the 12F509 doesn't work - there's no output after the copyright message - but the same code works using a 12F629.
12F62912F509Code:'=======================| RF RECEIVER |========================= 'MR26X629.BAS 'PIC12F629 @ 4MHz 478 words uses MPASM 'Pin 1 - Vdd 'Pin 2 - GPIO.5 'Pin 3 - GPIO.4 'Pin 4 - GPIO.3 'Pin 5 - GPIO.2 RS232 output @ 9600bps 'Pin 6 - GPIO.1 Receives up to 48 bits of PDM/PWM RF with lead-in of 2-9mS 'Pin 7 - GPIO.0 'Pin 8 - Vss '=============================================================== @ __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF DEFINE OSCCAL_1K 1 DEFINE OSC 4 DEFINE DEBUG_REG GPIO DEFINE DEBUG_BIT 2 DEFINE DEBUG_MODE 1 DEFINE DEBUG_BAUD 9600 RF VAR byte[6] period VAR word i VAR byte bits VAR byte bytes VAR byte sof VAR byte x VAR byte CMCON =%00000111 'disable comparators INTCON =%00000000 'disable interrupts OPTION_REG =%10000101 'TMR0 1:64 prescaler DEBUG "MR26X",13,10 Debug "Copyright ",169," 2009 dlh",13,10 init: RF[0]=0:RF[1]=0:RF[2]=0:RF[3]=0:RF[4]=0:RF[5]=0 While !GPIO.1:Wend 'wait rising edge TMR0=0 'clear TMR0 While GPIO.1:Wend 'wait falling edge sof=TMR0 'read TMR0 If (sof<29) Then init '1920µS If (sof>145) Then init '9280µS OPTION_REG=%10000011 'TMR0 1:16 prescaler While !GPIO.1:Wend 'wait rising edge TMR0=0 'clear TMR0 i=0 Repeat While GPIO.1 'wait falling edge If TMR0>155 Then break '2480µS Wend 'falling edge While !GPIO.1 'wait rising edge If TMR0>155 Then break '2480µS Wend 'rising edge Period=TMR0:TMR0=0 'clear TMR0 If (period<49) Then init '800µS If (period>93) Then '1500µS RF.0(i)=1 EndIf i=i+1 Until (i>47) break: If (i<12) Then init bytes=i/8 If i//8 Then bytes=bytes+1 EndIf x=i:GoSub sendhx For i = 0 to bytes-1 x=RF[i]:GoSub sendhx Next Debug 13,10 GoTo init sendhx: Debug "$" If x>>4<10 Then Debug x>>4+48 Else Debug x>>4+55 EndIf if x//16<10 Then Debug x//16+48 Else Debug x//16+55 EndIf Return EndCode:'=======================| RF RECEIVER |========================= 'MR26X509.BAS 'PIC12F509 @ 4MHz 654 words uses MPASM 'Pin 1 - Vdd 'Pin 2 - GPIO.5 'Pin 3 - GPIO.4 'Pin 4 - GPIO.3 'Pin 5 - GPIO.2 RS232 output @ 9600bps 'Pin 6 - GPIO.1 Receives up to 48 bits of PDM/PWM RF with lead-in of 2-9mS 'Pin 7 - GPIO.0 'Pin 8 - Vss 'TMR0 1:64 29=1.9mS,145=9.3mS - 1:16 49=0.8mS,93=1.5ms,155=2.5ms '=============================================================== @ __config _IntRC_OSC & _WDT_OFF & _MCLRE_OFF & _CP_OFF DEFINE OSCCAL_1K 1 DEFINE OSC 4 DEFINE DEBUG_REG GPIO DEFINE DEBUG_BIT 2 DEFINE DEBUG_MODE 1 DEFINE DEBUG_BAUD 9600 RF VAR byte[6] i VAR byte period VAR byte bytes VAR byte sof VAR byte x VAR byte OPTION_REG=%11000101 'TMR0 1:64 prescaler, disable TOCKI TRISIO=%111101 GPIO=%000000 Debug "MR26X",13,10 Debug "Copyright ",169," 2009 dlh",13,10 init: RF[0]=0:RF[1]=0:RF[2]=0:RF[3]=0:RF[4]=0:RF[5]=0 While !GPIO.1:Wend 'wait rising edge TMR0=0 'clear TMR0 While GPIO.1:Wend 'wait falling edge sof=TMR0 'read TMR0 If (sof<29) Then init '1920µS If (sof>145) Then init '9280µS OPTION_REG=%11000011 'TMR0 1:16 prescaler While !GPIO.1:Wend 'wait rising edge TMR0=0 'reset TMR0 i=0 Repeat While GPIO.1 'wait falling edge If TMR0>155 Then break '2480µS Wend 'falling edge While !GPIO.1 'wait rising edge If TMR0>155 Then break '2480µS Wend 'rising edge Period=TMR0:TMR0=0 'clear TMR0 If (period<49) Then init '800µS If (period>93) Then '1500µS RF.0(i)=1 EndIf i=i+1 Until (i>47) break: If (i<12) Then init bytes=i/8 If i//8 Then bytes=bytes+1 EndIf x=i:GoSub sendhx For i = 0 to bytes-1 x=RF[i]:GoSub sendhx Next 'Debug 32 'x=sof:GoSub sendhx Debug 13,10 GoTo init sendhx: Debug "$" If x>>4<10 Then Debug x>>4+48 Else Debug x>>4+55 EndIf if x//16<10 Then Debug x//16+48 Else Debug x//16+55 EndIf Return End





Bookmarks