OK. I'm going to critque the code now. On Mon, Jul 01, 2013 at 07:09:02AM +0800, Electronic Consultation wrote: > Yes this the first time I used assembly for PIC, most of the time I used = C. > if I want 1 ms on 20 Mhz processor with 1:64 prescaler ? It cannot be done. A 1:64 prescale on a 5 Mhz instruction clock will give you a 12.8 uS tick rate. There is no integer number of counts of 12.8 uS that will give you 1 mS. > Something like this ? > *on init :* > clrf TMR0 ;Set timer 0 to 0 - may not be needed >=20 > clrwdt ;Clear watchdog timer >=20 >=20 > bsf STATUS, RP0 ;SELECT BANK 1 >=20 > ; Set up timer interrupt > movlw b'10010110' ;weak portb pullups disabled -=20 > 1ms interrupt > movwf OPTION_REG ;select tmr0, 64d prescal, clock sou= rce >=20 > bcf STATUS, RP0 ;Select bank 0 >=20 > bcf INTCON,RBIE ; port B interrupt on change disa= ble >=20 > ;movlw b'1010000' ;enable global/timer0 interrupt > movlw b'10100000' ;enable global/timer0 interrupt > movwf INTCON ; Where exactly does the interrupt go? > *for 1ms:* > LedTimer EQU 0x0A Is LedTimer an address or a count. If it's an address then I don't think 0x0A is a General Purpose register on the 16F648A. Also take a read of my discussion earlier about the use of CBLOCK instead of equates. >=20 > clrf TMR0 ;Clear TMR0 and prescaler > banksel TMR0 > movlw 0xB2 ;Count=3DB2 > movwf TMR0 >=20 > timer1ms > movf LedTimer,f > btfsc STATUS,Z > decf LedTimer,Z > return Tthe timer1ms code makes little sense. First off it doesn't use Timer 0 in any way. If it's an interrupt service routine, it needs a retfie. If not, then is doesn't have a loop. If only decrements the LedTimer, which again is not a proper address, when it is already zero. You never assigned a value to LedTimer, so it's unclear if the decrement will ever execute. I really think you need to take a step back, stop trying to write code, and just explain what it is that you are trying to do. Right now the code is so confusing, that no one can really help you. As I always tell my students, programming isn't about writing code, it is about solving problems. Please explain the problem that you are trying to solve. Hope this helps, BAJ > --=20 > http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist --=20 Byron A. Jeff Chair: Department of Computer Science and Information Technology College of Information and Mathematical Sciences Clayton State University http://faculty.clayton.edu/bjeff --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .