![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | #1 (permalink) |
| New Member Join Date: Aug 2007 Location: Gold Coast
Posts: 4
| Hi All, I know this should be reallllly simple, but it is driving me insane... could someone please add comments to make the understanding of the code so simple that even I could understand it...? I know it should be as simple as 1-1=0 but I am still struggling with it... Delay movlw 20h ; .32 in W register movwf 21h ; placing .32 from W register into F (21h) Loop1 ; subroutine name decfsz 21h,1 ; decrementing 21h x 1 per loop (32,31,30....0 take 2 steps forward) goto loop1 ; counting down from 32 decfsz 22h,1 ; count down from 35 x 255 times(32+3;including instruction cycles) goto loop1 return By my calculation this should countdown 8925 cycles which is still to fast to see with the eye (using 4mhz crystal), but the LEd is flashing (by my estimate) at 1/4 second... thanks heaps |
| | |
| | #2 (permalink) |
| Experienced Member Join Date: Mar 2006 Location: Malaysia
Posts: 1,591
| Hi, What value is in 22h?
__________________ Superman Returns.. http://www.supermanhomepage.com/imag...an-returns.gif My friend created this account for me.. LOL http://bananasiong.myminicity.com oh.. somemore http://bananasiong.myminicity.com/env Exam T_T.T |
| | |
| | #5 (permalink) |
| New Member Join Date: Aug 2007 Location: Gold Coast
Posts: 4
| Thanks for the help, i really appreciate the responses... As you've probably figured out, i'm very much a newbie having a play...I've been working through the various tutorials, but this delay thing has just had me stumped for a long time! the code I'm using is ************************************************** ****** ; Tutorial for Intro Operators LIST p=16F628a ;tell assembler what chip we are using include "P16F628a.inc" ;include the defaults for the chip __config B'11110100011000' ;sets the configuration bits (SEE P98 OF DATASHEET) ; bit#'s 13 12 11 10 9 8 7 6 5 4 3 2 1 ; code - - - - LVP | MCLR | WDTE | | | ; prot. BOREN PWRT OSC select ERRORLEVEL -224 ; ignore this error during build ERRORLEVEL -302 ; ignore this error during build org 0000h ;org sets the origin, 0x0000 for the 16F628a, ;this is where the program starts running ; Turn CMCON (comparators RA3 & 4) OFF and makes more like 16f84a ; movlw b'0111' ;store bits to turn comparators OFF and enable I/O ; movwf 1fh ;send comparator bits to CMCON ;------------------------------------------------------------------------ ; leave data manipulation mode ; go into pic configure mode ; Prepare I and/or O ; and return to data manipulation mode bsf 03h,5 ;open pic configure mode (bank1) by setting (BitSetF) bank0, bit#5 ; bit#'s 76543210 movlw b'00000000' ;store I/O configuration - 0=output 1=input movwf 85h ;send configuration to TRISA (porta) movwf 86h ;send configuration to TRISB (portb) bcf 03h,5 ;return to pic control mode (bank0) by clearing (BitClearF) bank0, bit#5 ;------------------------------------------------------------------------ movlw 00h movwf 06h start movlw b'10000000' movwf 06h call Delay ;this waits for a while! movlw b'01000000' movwf 06h call Delay ;this waits for a while! movlw b'00100000' movwf 06h call Delay ;this waits for a while! movlw b'00010000' movwf 06h call Delay ;this waits for a while! movlw b'00001000' movwf 06h call Delay ;this waits for a while! movlw b'00000100' movwf 06h call Delay ;this waits for a while! movlw b'00000010' movwf 06h call Delay ;this waits for a while! movlw b'00000001' movwf 06h call Delay ;this waits for a while! movlw b'00000010' movwf 06h call Delay ;this waits for a while! movlw b'00000100' movwf 06h call Delay ;this waits for a while! movlw b'00001000' movwf 06h call Delay ;this waits for a while! movlw b'00010000' movwf 06h call Delay ;this waits for a while! movlw b'00100000' movwf 06h call Delay ;this waits for a while! movlw b'01000000' movwf 06h call Delay ;this waits for a while! goto start ;go back and do it again ; Delay movlw 20h movwf 21h loop1 decfsz 21h,1 goto loop1 decfsz 22h,1 goto loop1 decfsz 23h,1 goto loop1 return End ************************************************** ****** I understand your saying the address needs to be initialised...but I have no idea why the led's blink at 1/4 second rate...? I've also tried modifying the movlw 20h to 30h but it doesn't seem to change any on/off timing...? in my experimenting; if I add an additional loop (red coloured) it extends the time to about 20-30sec (haven't actually timed it but that is how long it seems) Thanks again |
| | |
| | #7 (permalink) | |
| New Member Join Date: Oct 2005 Location: Estonia
Posts: 11
| Quote:
According to my calculations (if there's no mistake) the whole delay takes total of 72963 cycles. With 4Mhz crystal this is the same amount microseconds or 72.962ms. LED blinking with 73ms on, 73ms off (period is then 146ms) should already be visible to eye as separate blinks. Code: Delay movlw 20h ; 1 cycle movwf 21h ; 1 cycle ; total so far: 2 cycles loop1: decfsz 21h, F ; takes 1 cycle default, 2 cycles when skipping (21h == 0) goto loop1 ; takes always 2 cycles ; TOTAL: 32x3-1 = 95 cycles decfsz 22h,1 ; assume 22h is zero at the beginning, takes 1 cycle unless register skipping, then takes 2 goto loop1 ; takes always 2 cycles return ; takes always 2 cycles ; TOTAL: 256x3x95-1+2+2 = 72 963 | |
| | |
| | #8 (permalink) |
| Experienced Member Join Date: Feb 2005
Posts: 30
| I have had a lot of success using Nigel Goodwin's tutorials. There is a led flashing tut and code for delays. I would go there for more knowledge on coding for delays and other functions. Good luck! http://www.winpicprog.co.uk fiveten |
| | |
| | #9 (permalink) |
| Experienced Member Join Date: Sep 2007 Location: Santiago, Chile
Posts: 80
| some good advice I got here one day was to use a C block. Code: list P=12f675
#include <p12f675.inc>
__config _INTRC_OSC_NOCLKOUT & _BODEN_OFF & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CPD_OFF & _CP_OFF
ERRORLEVEL -302
cblock 20h
irpulse, datagap, min
endc
bsf STATUS,RP0 ;bank 1
movlw 0x34
movwf ANSEL
movlw 0x00
movwf TRISIO ;set I/O
bcf STATUS,RP0
movlw 0x07 ;turn off comparitors
movwf CMCON
movlw 0x09
movwf ADCON0
start
__________________ jeremy Last edited by jeremygaughan; 12th May 2008 at 11:51 PM. |
| | |
| | #10 (permalink) | |
| Experienced Member Join Date: Sep 2007 Location: Vancouver, B.C.
Posts: 903
| Quote:
__________________ ========================= Futz's Microcontrollers & Robotics ========================= | |
| | |
| | #12 (permalink) | |
| Experienced Member Join Date: Sep 2007 Location: Vancouver, B.C.
Posts: 903
| Quote:
__________________ ========================= Futz's Microcontrollers & Robotics ========================= | |
| | |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
| | ||||
| Thread | Thread Starter | Forum | Replies | Latest |
| Atmel, assembly:displaying on lcd | Haidy | Micro Controllers | 13 | 11th February 2008 08:13 PM |
| PIC Christmas Light Project | amdkicksass | Micro Controllers | 28 | 9th July 2007 07:54 PM |
| calculator | sara_6252 | Micro Controllers | 8 | 1st June 2007 02:29 AM |
| LCD Alarm clock with PIC16F877 ( some pics included ) | pasanlaksiri | Micro Controllers | 10 | 22nd May 2007 10:36 PM |
| Modified LED Blinker | jonathan | Micro Controllers | 12 | 6th October 2003 01:42 PM |