Hi Tamas - I use the TechTools assembler and ICE which tends to use the 8051 mnemonics. They are literally one to one with the Microchip mnemonics. I have the WDT turned off. The problem generally only occurs on a cold startup. After the first startup, any others work correctly for the duration. Here is a little more code: ;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D ; CVASM16 INCLUDE FILE for the 12C509A ; Copyright (c) 2001 by TechTools ;support@tech-tools.com, sales@tech-tools.com ; 972-272-9392 FAX: 972-494-5814 ; ; - Last update: 04/23/01 ;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D ;DEVCODE 00509h ;ROMSIZE 1024 ;EESIZE 0 ;CORE _12bit ;PAGEBIT 1 ;MAXTRIS 0006 ;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D ;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D ; Main File Register Definitions ; GPIO Register BIT Definitions ;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D ;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D ;INDF EQU 0000h ;GP5 EQU GPIO.5 ;INDIRECT EQU 0000h ;GP4 EQU GPIO.4 ;TMR0 EQU 0001h ;GP3 EQU GPIO.3 ;PCL EQU 0002h ;GP2 EQU GPIO.2 ;STATUS EQU 0003h ;GP1 EQU GPIO.1 ;FSR EQU 0004h ;GP0 EQU GPIO.0 ;OSCCAL EQU 0005h ;GPIO EQU 0006h ;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D ;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D ; STATUS Register BIT Definitions ; Configuration (FUSE) BIT Definitions ;GPWUF EQU STATUS.7 ;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D ;PA0 EQU STATUS.5 ;_MCLRE_ON EQU 0FFFh ;NOT_TO EQU STATUS.4 ;_MCLRE_OFF EQU 0FEFh ;NOT_PD EQU STATUS.3 ;_CP_ON EQU 0FF7h ;Z EQU STATUS.2 ;_CP_OFF EQU 0FFFh ;DC EQU STATUS.1 ;_WDT_ON EQU 0FFFh ;C EQU STATUS.0 ;_WDT_OFF EQU 0FFBh ;_LP_OSC EQU 0FFCh ; ;_XT_OSC EQU 0FFDh ;_IntRC_OSC EQU 0FFEh ;_ExtRC_OSC EQU 0FFFh include 'C:\pictools\12C509.inc' FUSES _MCLRE_OFF FUSES _XT_OSC FUSES _WDT_OFF FUSES _CP_OFF ; PROGRAM: RCV232.SRC ; Taken from TechTools PIC Application Note: Receiving RS-232 Serial Data ; Written July 15, 1993 ; Revised February 24, 1996 (to accomodate SPASM v4.2) ; Revised May 3, 2000 ; This program receives a byte of serial data and leaves it in the register ; RCV_BYTE. The receiving baud rate is determined by the value of ; the constant bit_K and the clock speed of the PIC. See the table in the ; application note (above) for values of bit_K. For example, with the clock ; running at 4 MHz and a desired receiving rate of 4800 baud, make bit_K 50. ;For 9600 Baud make bit_K 23. reset begin bit_K =3D 23 ;Change this value for desired baudrate half_bit =3D bit_K/2 ;as shown in table. serial_in =3D GP0 serial_out =3D GP1 LED =3D GP2 LX200_Ver =3D GP3 org 8 ;Start of available RAM delay_cntr ds 1 ;Counter for serial delay routines bit_cntr_out ds 1 ;Number of transmitted bits msg_cntr ds 1 ;Offset in string xmt_byte ds 1 ;The transmitted byte bit_cntr_in ds 1 ;Number of received bits rcv_byte ds 1 ;The received byte delay_inner ds 1 ;inner delay for long delay loop char_cnt ds 1 ;Number of characters to send org 0h ;Start of code space ; Remember to change device info if programming a different PIC. Do not use RC ; devices. Their clock speed is not sufficiently accurate or stable for serial ; communication. ;*************************************************************************** ** ; Set up I/O ports. ;*************************************************************************** ** begin movlw 00001001b ;Use GP0 for serial input, ;GP3 for version select TRIS gpio ;and store. movlw 10000000b option call FLASH_LED call general_delay_out call general_delay_out ;*************************************************************************** ** ; Check to see if the telescope is a PRE or POST LX200 ;*************************************************************************** ** :SEND_DATA jb LX200_Ver,:prepare_POST ;if high jump to post, else goto LX200_early ----- ------- more code ;*************************************************************************** ** ; RECEIVE section of code ;*************************************************************************** ** :start_bit btfsc serial_in ;Detect start bit. Change to ;btfss from btfsc serial_in if using ------------- ------------ more code ;*************************************************************************** ** ; DATA received from LX200 - first check to see if it is a POST or a ; PRE model of the LX200. ;*************************************************************************** ** sb LX200_Ver ;if high skip next, else post model jmp :check_pre ;low so jump to pre model movlw 01Bh ;compare for Escape xor w,rcv_byte jz FLASH_LED_START ;if zero after xor, flash led jmp ERROR_LED ;else go to show error on the LED :check_pre movlw 'P' ;check for a P xor w,rcv_byte jz FLASH_LED_START ;if zero after xor then jump movlw 'A' ;check for A xor w,rcv_byte jz FLASH_LED_START ;if zero after xor then jump movlw 'L' ;check for L xor w,rcv_byte jz FLASH_LED_START ;if zero after xor then jump ;*************************************************************************** ** ; Error occurred on receive (wrong character - turn the LED on for ; a period of time ;*************************************************************************** ** ERROR_LED setb LED ;turn on the LED call general_delay_out call general_delay_out call general_delay_out call general_delay_out call general_delay_out call general_delay_out call general_delay_out call general_delay_out call general_delay_out call general_delay_out call general_delay_out call general_delay_out call general_delay_out call general_delay_out call general_delay_out call general_delay_out clrb LED ;turn off the LED jmp SLEEP_TIME ;*************************************************************************** ** ; Proper character was received, sl flash the LED a number of times ;*************************************************************************** ** FLASH_LED_START call FLASH_LED jmp SLEEP_TIME FLASH_LED setb LED ;Flash the LED if value is correct call general_delay_out call general_delay_out clrb LED call general_delay_out call general_delay_out setb LED call general_delay_out call general_delay_out clrb LED call general_delay_out call general_delay_out setb LED call general_delay_out call general_delay_out clrb LED call general_delay_out call general_delay_out setb LED call general_delay_out call general_delay_out clrb LED call general_delay_out call general_delay_out setb LED call general_delay_out call general_delay_out clrb LED call general_delay_out call general_delay_out setb LED call general_delay_out call general_delay_out clrb LED call general_delay_out call general_delay_out setb LED call general_delay_out call general_delay_out clrb LED ;Turn off the LED call general_delay_out call general_delay_out ret ;*************************************************************************** ** ; Duty is over, so go to sleep to reduce power consumption ;*************************************************************************** ** SLEEP_TIME sleep ;Power down ;*************************************************************************** ** ; Characters to send if model is a POST LX200 ;*************************************************************************** ** string_post jmp pc+w ;LX200 Post mid-93 initiate string retw 0ffh,0ffh,0ffh,02ah ;*************************************************************************** ** ; Characters to send if model is a PRE LX200 ;*************************************************************************** ** string_pre jmp pc+w ;LX200 Pre mid-93 initiate string retw 048h,006h general_delay_out mov delay_cntr,0ffh :loop_1 nop mov delay_inner, 0a0h :loop_2 djnz delay_inner, :loop_2 djnz delay_cntr, :loop_1 ret ; To change the baud rate, substitute a new value for bit_K at the beginning of ; this program. ; This delay loop takes four instruction cycles per loop, plus eight ; instruction cycles for other operations (call, mov, the final djnz, and ret). ; These extra cycles become significant at higher baud rates. The values for ; bit_K in the table take the time required for additional instructions into ; account. bit_delay mov delay_cntr,#bit_K :loop nop djnz delay_cntr, :loop ret ; This delay loop is identical to bit_delay above, but provides half the delay ; time. start_delay mov delay_cntr,#half_bit :loop nop djnz delay_cntr, :loop ret David David V. Fansler s/v Annabelle dfansler@dv-fansler.com www.dv-fansler.com -----Original Message----- From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] On Behalf Of Tamas Rudnai Sent: Sunday, February 07, 2010 5:35 PM To: Microcontroller discussion list - Public. Subject: Re: 12C09Timer Problem I have never heard of 'mov', 'djnz' and 'ret' instructions in conjunction to the PIC Baseline family. Also there is no need semicolon in front of the label. Are you using a different Assembly than MPASM or some customized macro set? It is hard to tell the exact timing of the delay routine if the instruction timing of each step is unknown. Anyway, I assume that in your macro set everything is going all right, so then the different timing is another issue. Maybe you have a WDT switched on you forget to clear? Tamas On Sun, Feb 7, 2010 at 9:57 PM, David V. Fansler wrote: > After a long hiatus from PICs, I picked up a project recently that I am > using a 12C509(A) for the first time. =A0The project is simple - when powered > on check a jumper - if jumper high send 4 characters through a bit bang > serial port (9600,8,n,1), if jumper low send 2 characters through the bit > bang serial port (9600,8,n,1). =A0Then wait for the first returned charac= ter > and verify if it is what was expected. > > > > All that works. =A0As a visual indicator, I have a LED that flashes sever= al > times on power up, flashes once when sending data, and if the returned data > is good it flashes several more times and the 12C509 goes to sleep. =A0If the > returned character is not valid, it turns on for a short period of time and > goes out, and again the PIC goes to sleep. =A0The problem I am having is that > the flashing occurs at two different rates. =A0The fast rate is 50ms per > on/off cycle and the slow rate happens so in often I have not been able to > clock it, but it is about 1s per on/off cycle. =A0I am running an external > 4.00 MHz oscillator. > > > > Here is the code for the loop > > general_delay_out > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0mov =A0 = =A0 =A0 delay_cntr,0ffh > > :loop_1 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 nop > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0mov =A0 = =A0 =A0 delay_inner, 0a0h > > :loop_2 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 djnz =A0 =A0 =A0 delay_inner, :lo= op_2 > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0djnz =A0 = =A0 =A0 delay_cntr, :loop_1 > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0ret > > > > Thanks, > > > > David > > > > David V. Fansler > > s/v Annabelle > > dfansler@dv-fansler.com > > www.dv-fansler.com > > > > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > -- = /* www.mcuhobby.com */ int main() { char *a,*s,*q; printf(s=3D"/* www.mcuhobby.com */ int main() { char *a,*s,*q; printf(s=3D%s%s%s, q=3D%s%s%s%s,s,q,q,a=3D%s%s%s%s,q,q,q,a,a,q); }", q=3D"\"",s,q,q,a=3D"\\",q,q,q,a,a,q); } -- = http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist -- = http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist