Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Led Blink using PIC & timer

Status
Not open for further replies.

neelam29

New Member
hi friends,
can anyone please help me in finding out myh mistake. Actually i'm trying to blink a led using timer 0 of PIC16F628A but can't. here's the code:-

Code:
LIST   p=16F628A      ;tell assembler what chip we are using 
   include "P16F628A.inc"      ;include the defaults for the chip 


   cblock    0x20          ;start of general purpose registers 
      count1          ;used in delay routine 
      counta          ;used in delay routine 
      countb          ;used in delay routine 
   endc 
    
   org   0x0000            ;org sets the origin, 0x0000 for the 16F628, 
      GOTO   start               ;this is where the program starts running    


   org   0x04                  GOTO   OVFL_ISR               ;this is where the ISR starts running    



   movlw   0x07 
   movwf   CMCON         ;turn comparators off (make it like a 16F84) 




initialize 
   clrf       PORTB    

   bsf    STATUS,   RP0      ;select bank 1 
      movlw    b'00000000'      ;set PortB all outputs 
      movwf    TRISB 
    
   bcf      STATUS,   RP0      ;select bank 0 
   retlw   0x00 



OVFL_ISR 
    
   comf   PORTB, F 
   bcf      INTCON, T0IE 
   retfie 





start 
   call   initialize 
    
   clrf   TMR0 
   clrf   INTCON 
   bsf    STATUS,   RP0      ;select bank 1 
   movlw    b'00110001' 
   bsf      INTCON, T0IE 
   bsf      INTCON, GIE 


Loop    
    
   goto   Loop         ;go back and do it again 



   end

i would appretiate any help, Thank you.
 
Hey neelam, what a coincidence, I've been working on the exact same thing today, with the same PIC. I'm also very new to microcontrollers, and have just started getting my feet wet with MPLAB today. What error are you getting? It looks like you just copied straight from Nigel's tutorial so you couldn'tve mis-typed anything.
 
Hiya Neelam,
Eh mate I just copied your code and ran it in mplab and here are the results of trying to build it.

Executing: "C:\Program Files\Microchip\MPASM Suite\MPAsmWin.exe" /q /p16F628A "z.asm" /l"z.lst" /e"z.err"
Warning[205] C:\BACKUP DATA\Z.ASM 1 : Found directive in column 1. (LIST)
Error[113] C:\BACKUP DATA\Z.ASM 15 : Symbol not previously defined (GOTO)
Error[112] C:\BACKUP DATA\Z.ASM 15 : Missing operator
Error[118] C:\BACKUP DATA\Z.ASM 19 : Overwriting previous address contents (0000)
Error[118] C:\BACKUP DATA\Z.ASM 19 : Overwriting previous address contents (0000)
Message[302] C:\BACKUP DATA\Z.ASM 30 : Register in operand not in bank 0. Ensure that bank bits are correct.
Halting build on first failure as requested.
BUILD FAILED: Thu Feb 23 16:30:15 2006

Now each error is shown why it won't build and it gives you the offending line and the reason. On first looking at your code 1 basic parameter is missing the config word!!! Next read the datasheet on how to setup timer0 and then redo your code. It's not hard at all to setup timer0 and get an led to flash on overflow but reading the datasheet first is a must for anyone not just beginners.

Cheers Bryan :D
 
As well as the errors that Brian pointed out, there is a error that the compiler cannot pick up.

When you have corrected line 15 so that it is 2 lines.
I.E.
Code:
   org   0x04                  
   GOTO   OVFL_ISR               ;this is where the ISR starts running
You then have 2 lines which load 7 into CMCON. This code can never be executed. You need to move them lines down so they come after the initialize label.

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top