A Better Mouse Trap. Consumer Appliance, Widget, Gadget APPLICATION OPERATION: Ontario, Canada

Similar documents
Embedded Systems. PIC16F84A Sample Programs. Eng. Anis Nazer First Semester

Discrete Logic Replacement A Keypad Controller for Bi-directional Key Matrix

Lecture (04) PIC16F84A (3)

Assembly Language Instructions

PIC 16F84A programming (II)

Instuction set

Chapter 4 Sections 1 4, 10 Dr. Iyad Jafar

Chapter 13. PIC Family Microcontroller

PIC16F87X 13.0 INSTRUCTION SET SUMMARY INSTRUCTIONS DESCRIPTIONS

LAB WORK 2. 1) Debugger-Select Tool-MPLAB SIM View-Program Memory Trace the program by F7 button. Lab Work

16.317: Microprocessor Systems Design I Fall 2013 Exam 3 Solution

UNIVERSITY OF ULSTER UNIVERSITY EXAMINATIONS : 2001/2002. Semester 2. Year 2 MICROCONTROLLER SYSTEMS. Module Code: EEE305J2. Time allowed: 3 Hours

SOLUTIONS!! DO NOT DISTRIBUTE!!

Chapter 5 Sections 1 6 Dr. Iyad Jafar

S w e d i s h c r. w e e b l y. c o m j a l i l a h m e l i v e. c o m Page 1

CENG 336 INT. TO EMBEDDED SYSTEMS DEVELOPMENT. Spring 2006

TOPIC 3 INTRODUCTION TO PIC ASSEMBLY LANGUAGE. E4160 Microprocessor & Microcontroller System. Prepared by : Puziah Yahaya JKE, POLISAS / DEC 2010

Lesson 14. Title of the Experiment: Introduction to Microcontroller (Activity number of the GCE Advanced Level practical Guide 27)

UNIVERSITY OF ULSTER UNIVERSITY EXAMINATIONS : 2001/2002 RESIT. Year 2 MICROCONTROLLER SYSTEMS. Module Code: EEE305J1. Time allowed: 3 Hours

Discrete Logic Replacement Message Dispatch Engine

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING. EE6008 Microcontroller based system design

University of Jordan Faculty of Engineering and Technology Department of Computer Engineering Embedded Systems Laboratory

EEE111A/B Microprocessors

Controller Provides Display of Monitored Process Deviation

16.317: Microprocessor-Based Systems I Spring 2012

Flow Charts and Assembler Programs

D:\PICstuff\PartCounter\PartCounter.asm

Beacon Keyers Using PIC s. Dave Powis, DL/G4HUP

Dept. of Computer Engineering Final Exam, First Semester: 2016/2017

More (up a level)... Connecting the Nokia 3510i LCD to a Microchip PIC16F84 microcontroller

EECE.3170: Microprocessor Systems Design I Summer 2017 Homework 5 Solution

DERTS Design Requirements (1): Microcontroller Architecture & Programming

PIC12C5XX. 8-Pin, 8-Bit CMOS Microcontroller. CMOS Technology: Devices included in this Data Sheet: High-Performance RISC CPU: Pin Diagram

Section 11. Timer0. Timer0 HIGHLIGHTS. This section of the manual contains the following major topics:

APPLICATION NOTE Wire Communication with a Microchip PICmicro Microcontroller

PTK8756B 8 Bit Micro-controller Data Sheet

ECE Test #1: Name

Introduction to PIC Programming

SOLUTIONS!! DO NOT DISTRIBUTE PRIOR TO EXAM!!

Electromechanical Timer Replacement

Performance & Applications

EE6008-Microcontroller Based System Design Department Of EEE/ DCE

Designed to GO... Universal Battery Monitor Using the bq2018 Power Minder IC. Typical Applications. Features. Figure 1. bq2018 Circuit Connection

Interfacing PIC Microcontrollers. ADC8BIT2 Schematic. This application demonstrates analogue input sampling

Week1. EEE305 Microcontroller Key Points

PIC10F200/202/204/206 Data Sheet

Introduction to PIC Programming

ECE 354 Introduction to Lab 2. February 23 rd, 2003

/* PROGRAM FOR BLINKING LEDs CONEECTED TO PORT-D */

PIC10F200/202/204/206

Section 31. Instruction Set

Outline. Micriprocessor vs Microcontroller Introduction to PIC MCU PIC16F877 Hardware:

PART TWO LISTING 8 PROGRAM TK3TUT8 MOVF PORTA,W ANDLW B ADDWF COUNT,F MOVF COUNT,W MOVWF PORTB GOTO LOOP

APPLICATION NOTE 2361 Interfacing an SPI-Interface RTC with a PIC Microcontroller

16.317: Microprocessor-Based Systems I Summer 2012

ECE 354 Computer Systems Lab II. Interrupts, Strings, and Busses

Introduction to PIC Programming

PIC16C Pin, 8-Bit CMOS Microcontroller. Device included in this Data Sheet: Special Microcontroller Features: High-Performance RISC CPU:

AN587. Interfacing to an LCD Module. Interfacing to an LCD Module INTRODUCTION OPERATION CONTROL SIGNAL FUNCTIONS TABLE 2: CONDITIONAL ASSEMBLY FLAGS

Section 4. Architecture

When JP1 is cut, baud rate is Otherwise, baud rate is Factory default is that JP1 is shorted. (JP1 is jumper type in some model)

Weekly Report: Interactive Wheel of Fortune Week 4 02/014/07-02/22/07 Written by: Yadverinder Singh

PIC16F84A 7.0 INSTRUCTION SET SUMMARY INSTRUCTIONS DESCRIPTIONS

PIC12CE5XX. 8-Pin, 8-Bit CMOS Microcontroller with EEPROM Data Memory. Devices Included in this Data Sheet: Pin Diagram: High-Performance RISC CPU:

NH-67, TRICHY MAIN ROAD, PULIYUR, C.F , KARUR DT. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING COURSE MATERIAL

PIC16C Pin, 8-Bit CMOS Microcontroller. Device included in this Data Sheet: Special Microcontroller Features: High-Performance RISC CPU:

Fortune. Semiconductor Corporation 富晶半導體股份有限公司. 8-bit MCU with 1k program ROM, 64-byte RAM, 1 R2F module and 3 13 LCD driver. TD Rev. 1.

Jordan University of Science and Technology Electrical Engineering Department Microcontrollers and Embedded Systems Spring 2011

Application Note - PIC Source Code v1.1.doc

Micro II and Embedded Systems

Hardware Interfacing. EE25M Introduction to microprocessors. Part V. 15 Interfacing methods. original author: Feisal Mohammed

Hi Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

CONNECT TO THE PIC. A Simple Development Board

TM57PA20/ TM57PA40. 8 Bit Microcontroller. User Manual. Tenx reserves the right to change or discontinue this product without notice.

CHAPTER 6 CONCLUSION AND SCOPE FOR FUTURE WORK

Binary Outputs and Timing

Electromechanical Switch Replacement Smart Switch for Car Windscreen Wiper Control

Hi Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

DESIGN AND FABRICATION OF FARE METER OF TAXICAB USING MICROCONTROLLER

PIC PROGRAMMING START. The next stage is always the setting up of the PORTS, the symbol used to indicate this and all Processes is a Rectangle.

Section 13. Timer0 HIGHLIGHTS. Timer0. This section of the manual contains the following major topics:

PIC16C84. 8-bit CMOS EEPROM Microcontroller PIC16C84. Pin Diagram. High Performance RISC CPU Features: CMOS Technology: Peripheral Features:

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING. EE Microcontroller Based System Design

movwf prevcod ; a new button is pressed - rcnt=3 movwf (mtx_buffer+1) movlw 3 movwf rcnt

Wireless Model Rocket Igniter, William Grill, Riverhead Systems

These 3 registers contain enable, priority,

PIC16C52. EPROM-Based 8-Bit CMOS Microcontroller PIC16C52. Pin Diagrams. Feature Highlights. High-Performance RISC CPU. Peripheral Features

Chapter 3: Further Microcontrollers

PIC Discussion. By Eng. Tamar Jomaa

PIC12F529T48A Data Sheet

SOLAR TRACKING SYSTEM USING PIC16F84A STEPPER MOTOR AND 555TIMER

/ 28 HLL assembly Q4: Conditional instructions / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10

Section 14. Timer1 HIGHLIGHTS. Timer1. This section of the manual contains the following major topics:

Arithmetic,logic Instruction and Programs

PIC16F8X. 8-Bit CMOS Flash/EEPROM Microcontrollers PIC16F8X PIC16CR8X. Pin Diagram. Devices Included in this Data Sheet:

Done 1 NVB THF TLF T/R POL 1SHOT. Figure 1: Status register

PIN DESCRIPTION Name I/O Description VDD P VSS P 5V Power from USB cable Ground RC6M O X1 I Test/OTP mode clock in Internal clock output (6MHz) VPP I

Microchip AN528 产品用户参考手册 单片机集成方案全方位解决服务商 优质智能电子产品 芯 方案解决商 深圳市英锐恩科技有限公司 深圳市英锐恩科技有限公司 ENROO-TECH(SHENZHEN)CO.,LTD 中国 深圳市福田区福华路嘉汇新城汇商中心 27 楼 2701

ALU and Arithmetic Operations

Section 16. Basic Sychronous Serial Port (BSSP)

Transcription:

A Better Mouse Trap Author: APPLICATION OPERATION: My application uses a PIC12C508 to produce realistic sounding mouse-like coos that all mice are sure to find seductive. The entire circuit should be imbedded in, or at least placed, near a baited mouse-trap for best effect. The heart of the circuit is a pseudo-random number generator that determines both the time between squeaks, and the number of chirps in each squeak. In operation, the watchdog timer is used to wake the mouse up at a constant half-second rate. If the randomly determined, one to sixteen periods have passed, the mouse will emit a squeak. Squeaks consist of from one to four chirps, and each chirp is a tone that sweeps from about 5KHz to 10KHZ, in about 30mSec. The circuit operates on two AAA dry cells, and drives a standard piezoelectric buzzer through a 4.7K resistor via a two pin push-pull output. No other components are required. Block Diagram: Operation is straight-forward, as described above. Flow Chart: Jim Nagy Ontario, Canada email: nagy@wwdc.com Operation is straight-forward, as described above. Graphical hardware representation: This is probably described easier than I can draw it: Unused pins 2, 3, 4, and 5 are all connected to pin 1. Pin 7 has a 4.7K resistor connected to it with the other side of the resistor connected to either one of the wires on a piezoelectric buzzer. The other buzzer wire goes to pin 6. The value of the 4.7K resistor is not critical. It should be at least 1K to limit the current into the buzzer, and increased from there, to limit the volume to a pleasing level (depends on the efficiency of the buzzer). The heart of the circuit is an 8-pin PIC12C508. Two AAA dry cells are connected in series to form a 3V supply, then connected with the positive lead to pin 1 of the PIC12C508, and the negative one to pin 8. Microchip Technology Incorporated, has been granted a nonexclusive, worldwide license to reproduce, publish and distribute all submitted materials, in either original or edited form. The author has affirmed that this work is an original, unpublished work and that he/she owns all rights to such work. All property rights, such as patents, copyrights and trademarks remain with author. 1998 Microchip Technology Inc. DS40160A/5_005-page 1

APPENDIX A: SOURCE CODE MouseTrap ========= by Jim Nagy, Sept. 1997 A solid state mouse (the four legged kind) simulator, using the PIC12C508. This circuit produces realistic-sounding mouse-like coos that all mice are sure to find seductive. The circuit should be installed near a baited mouse-trap for best effect. This circuit is powered by a 3V source, and directly drives a piezoelectric buzzer. Circuit connections are as follows: A piezoelectric buzzer is connected through a series 4.7K resistor to pins 6&7 (GP0&1) +3V is connected to pin 1, gnd to pin 8 pins 2,3,4, and 5 should be tied to either pin 1 or 8 ****************************** Program equates TMin EQU D'16' Mouse chirps are frequency sweeps from about 5-10KHz TMax EQU D'32' the freq. is approx 166000/T Standard Equates W EQU 0 F EQU 1 GPWUF EQU 7 PA0 EQU 5 TO EQU 4 PD EQU 3 Z EQU 2 Zero EQU 2 DC EQU 1 C EQU 0 Carry EQU 0 MCLRDisabled EQU 0 MCLREnabled EQU H'10' CodeProtect EQU 0 NoCodeProtect EQU H'08' WDTDisabled EQU 0 WDTEnabled EQU H'04' IntRCOsc EQU H'02' ExtRCOsc EQU H'03' XTOsc EQU H'01' LPOsc EQU 0 '508 Registers INDF EQU H'00' TMR0 EQU H'01' PCL EQU H'02' STATUS EQU H'03' FSR EQU H'04' OSCCAL EQU H'05' GPIO EQU H'06' program variables LByte EQU H'07' random number variables HByte EQU H'08' numbers are generated as 2bytes+carry CBit EQU H'09' DS40160A/5_005-page 2 1998 Microchip Technology Inc.

RNum EQU H'07' Generated random number...same as 'LByte' WDTimes EQU H'0A' Mouse only chirps after 'WDTimes' wakeups Count EQU H'0A' Dual use reg - only used during a chirp ChirpCnt EQU H'0B' CycleCnt EQU H'0C' DelayCnt EQU H'0D' # of chirps in the squeak counts cycles during a chirp delay counter for waveform generation Setting the ID words... ORG H'0200' ID0 Data.WH'0000' ID1 Data.WH'0000' ID2 Data.WH'0003' ID3 Data.WH'0008' and the Fuses... ORG H'0FFF' CONFIG Data.W MCLRDisabled + NoCodeProtect + WDTEnabled + IntRCOsc PIC starts here on power up... ORG H'00' MOVWFOSCCAL store the factory osc. calibration value subroutines must be in the low page, so jump to higher memory... BTFSCSTATUS,TO check if we're here from WDT timeout GOTOInit no, do a full reset BTFSCSTATUS,PD was a timeout, but was it a wakeup call GOTOInit no - it was a code error GOTOMain yes, was a wakeup Chirp Each mouse squeak consists of a series of 1 to 4 chirps. Each chirp lasts about 30mS, and consists of 12 cycles at each frequency from a min set by TMax, to the maximum freq, set by TMin: ChirpMOVLWTMax get the initial waveform period MOVWF Count and save it ch1 MOVLW D'12' 12 cycles at each frequency MOVWF CycleCnt ch2 MOVF Count,W load the count(delay) value BSF GPIO,0 and produce one cycle CALL DelayLoop BCF GPIO,0 MOVF Count,W BSF GPIO,1 CALL DelayLoop BCF GPIO,1 DECFSZ CycleCnt,F keep repeating GOTO ch2 DECF Count,F reduce count to increase frequency MOVLW TMin SUBWF Count,W compare to the min period value BTFSC STATUS,Carry C is clear if Count<TMin 1998 Microchip Technology Inc. DS40160A/5_005-page 3

GOTO ch1 RETLW 0 DelayLoop A simple delay routine... DelayLoop MOVWF DelayCnt save the count value d1 DECFSZ DelayCnt,F count down, GOTO d1 and loop, RETLW 0 'til we're done Random Generates a 'random' byte in RNum. Maintains a 2 byte shift register (LByte and HByte) that has an input provided by the XNOR of the inverse of the 13th bit and the carry out bit. Generates one bit at a time, so calls itself 8 times to form a byte. Random MOVF HByte,F have to catch the special case where all BTFSS STATUS,Zero 16 bits are 0 GOTO r1 MOVF LByte,F BTFSS STATUS,Zero GOTO r1 MOVF TMR0,W both bytes are zero, seed with the low byte MOVWF LByte with the timer contents BTFSS STATUS,Zero but even the timer might read zero GOTO r1 DECF LByte,F so then, just seed with FF r1 7 calls and a fall-through gives 8 calls... RLoopMOVF CBit,F the XNOR is based on the carry and 13th bits BTFSS STATUS,Zero check the 'carry bit' GOTO CarryWas1 CarryWas0 CarryWas1 SetCarry BTFSC HByte,4 C=0, so check bit 13 INCF CBit,F if it's 1, we'll rotate in a 1 GOTO SetCarry CLRF CBit assume the new carry will be 0 BTFSS HByte,4 which it will be if bit13 is 1 INCF CBit,F else set CBit to 1 (b13=0) CLRW start with W=0 ADDWF CBit,F adding 0 to anything forces C=0 BTFSS STATUS,Zero if CBit=0, go on SUBWF CBit,F else, set C=1 RotateRLF LByte,F rotate the new bit into the shift reg RLF HByte,F CLRF CBit then set CBit to the current value of C DS40160A/5_005-page 4 1998 Microchip Technology Inc.

BTFSC STATUS,Carry INCF CBit,F RETLW 0 Wait Provides a 50mS delay - careful it uses Count reg! Wait MOVLW D'65' MOVWF Count loop counter s1 MOVLW H'FF' CALL DelayLoop delay 0.77mS DECFSZ Count,F and repeat GOTO s1 RETLW 0 Power On jumps to here...either Init, or Main Init CLRF WDTimes force a single chirp this time CLRF ChirpCnt INCF ChirpCnt,F Main CLRF GPIO Init the port - WDT always clears it MOVLW B'00111100' GP0 and GP1 are outputs, others are inputs TRIS GPIO CLRWDT Set up the timers... MOVLW B'11001101' int clock to TMR0, WDT uses /32 (0.5s wakeup) OPTION no pullups, and no wakeup on change MOVF WDTimes,F check if WD has timed out enough times BTFSC STATUS,Zero GOTO Squeak counted down to zero - ready for a squeak DECF WDTimes,F else count this time, SLEEP and wait m1 CALL Wait A squeak is chirpcnt chirps Squeak CALL Chirp with pauses in between DECFSZ ChirpCnt,F GOTO m1 CLRWDT been busy... make sure we won't be interrupted CALL Random let's get another random byte MOVF RNum,W and determine the next ChirpCount... ANDLW B'00000011' only use the last 2 bits for the count MOVWF ChirpCnt but we can't have zero squeaks, INCF ChirpCnt,F so add 1 END SWAPF RNum,W now calculate the wakeup delay... ANDLW B'00001111' only use the last 4 bits (0-8 sec delay) MOVWF WDTimes SLEEP that's all folks 1998 Microchip Technology Inc. DS40160A/5_005-page 5

NOTES: DS40160A/5_005-page 6 1998 Microchip Technology Inc.