;Title 1khurts.asm ;a 1.00kHz square wave generator. ;program runs a xtal oscillator PIC16f872 to exactly 1000 hertz. ;comments: firstname.lastname@example.org include "P16f872.inc" ; use definition file for 16F872 ; configure the chip for a crystal oscillator, with code protection and watchdog timer off. __CONFIG _CP_OFF & _XT_OSC &_WDT_OFF ; define RAM =, give RAM registers names. CBLOCK 0x20 ; RAM starts at address 20h d1 ENDC ; org 0x0000 ; start address = 0000h ; INITIALISE PORTS ; binary used to see individual pin level movlw b'00000000' ; all port pins = low movwf PORTA movlw b'00000000' movwf PORTB movlw b'00000000' movwf PORTC bsf STATUS,RP0 ; set RAM Page 1 for TRIS registers ; initialize ports ; set all pins to outputs, and analog pins to digital. movlw b'00000000' ; all IO pins = outputs movwf TRISA movlw b'00000000' movwf TRISB movlw b'00000000' movwf TRISC movlw b'00000110' ; all analog pins = digital movwf ADCON1 bcf STATUS,RP0 ; back to RAM page 0 ; LED FLASH LOOP Loop bsf PORTC,4 ; RC4 = high nop ; these two nop's make each half of cycle the same delay. nop call Delay bcf PORTC,4 ; RC4 = low call Delay goto Loop ; trial 1kHz delay subroutine ; delay is period/2 ; 1kHz = 1000/s => period = .001 = 1ms ; 1ms/2 = 0.5 ms = .0005s ; 0.0005x1Mips = 500 instruction cycles (clock is 4MHz). ; 500 - 5 (overhead of calling delay, and looping) = 495 Delay movlw 0xA4 ;A4 = 164, see below, Delay is 2 instruction cycles so 495 - 2 = 493. movwf d1 Count decfsz d1 ;493 required by Count, Count is 3 instructions each loop + 1 for skip, 492, w/o skip 492/3=164=A4 goto Count return END
|file: /Techref/microchip/1khurts.htm, 2KB, , updated: 2004/2/4 14:15, local time: 2015/11/28 16:08,
|©2015 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?|
<A HREF="http://www.piclist.com/techref/microchip/1khurts.htm"> PIC 16F872 oscillator at exactly 1000 hertz</A>
|Did you find what you needed?|
PICList 2015 contributors:
o List host: MIT, Site host massmind.org, Top posters @20151128 RussellMc, IVP, James Cameron, Neil, embedded systems, Bob Blick, Richard R. Pope, Isaac Marino Bavaresco, alan.b.pearce, John Gardner,
* Page Editors: James Newton, David Cary, and YOU!
* Roman Black of Black Robotics donates from sales of Linistep stepper controller kits.
* Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters.
* Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated!
* Contributors: Richard Seriani, Sr.
Welcome to www.piclist.com!