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

Similar documents
D:\PICstuff\PartCounter\PartCounter.asm

Lecture (04) PIC16F84A (3)

CENG 336 INT. TO EMBEDDED SYSTEMS DEVELOPMENT. Spring 2006

Application Note - PIC Source Code v1.1.doc

PIC 16F84A programming (II)

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

16.317: Microprocessor Systems Design I Fall 2013 Exam 3 Solution

PIC16F87X 13.0 INSTRUCTION SET SUMMARY INSTRUCTIONS DESCRIPTIONS

Chapter 4 Sections 1 4, 10 Dr. Iyad Jafar

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

Assembly Language Instructions

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

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

Flow Charts and Assembler Programs

ECE Test #1: Name

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

Chapter 13. PIC Family Microcontroller

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

Instuction set

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

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

Introduction to PIC Programming

Controller Provides Display of Monitored Process Deviation

SOLUTIONS!! DO NOT DISTRIBUTE!!

Discrete Logic Replacement Message Dispatch Engine

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

16.317: Microprocessor-Based Systems I Summer 2012

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

EEE111A/B Microprocessors

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

16.317: Microprocessor-Based Systems I Spring 2012

Section 31. Instruction Set

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

Introduction to PIC Programming

APPLICATION NOTE Wire Communication with a Microchip PICmicro Microcontroller

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

ECE Homework #3

4.5.1) The Label Field ) The Mnemonic Field. 4.5) Assembly Language Program Structure A PIC18 ALP consists of 3 type of statements:

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

Arithmetic,logic Instruction and Programs

Chapter 5 Sections 1 6 Dr. Iyad Jafar

PIC16F84A 7.0 INSTRUCTION SET SUMMARY INSTRUCTIONS DESCRIPTIONS

/ 40 Q3: Writing PIC / 40 assembly language TOTAL SCORE / 100 EXTRA CREDIT / 10

SOLAR TRACKING SYSTEM USING PIC16F84A STEPPER MOTOR AND 555TIMER

Week1. EEE305 Microcontroller Key Points

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

Chapter 5. Problems All programming problems should include design pseudo code either as a separate design document on embedded comments in the code.

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

CONNECT TO THE PIC. A Simple Development Board

Binary Outputs and Timing

Here is a sample of the Hellschrieber sent by this project: Following is the PIC MPASM Source Code for Version 0.03 of the Beacon:

Section 4. Architecture

Performance & Applications

Figure 1: Pushbutton without Pull-up.

Chapter 3: Further Microcontrollers

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

SOLUTIONS!! DO NOT DISTRIBUTE PRIOR TO EXAM!!

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)

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

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

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

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

President Alan VK6ZWZ Acting Sec. Don VK6HK Vice President Terry VK6ZLT Treasurer Ces VK6AO

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.

PTK8756B 8 Bit Micro-controller Data Sheet

Lesson 4 Fun with W and F

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

Outlines. PIC Programming in C and Assembly. Krerk Piromsopa, Ph.D. Department of Computer Engineering Chulalongkorn University

Arithmetic and Logic Instructions. Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

EECE.3170: Microprocessor Systems Design I Summer 2017

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

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

PIC Discussion. By Eng. Tamar Jomaa

Introduction to PIC Programming

Electromechanical Timer Replacement

Electromechanical Switch Replacement Smart Switch for Car Windscreen Wiper Control

Q1: Multiple choice / 20 Q2: Protected mode memory accesses. / 40 Q3: Reading PIC. / 40 assembly language TOTAL SCORE / 100

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

PICDEM-1 USER S GUIDE

The University of Texas at Arlington Lecture 5

Section 30. In-Circuit Serial Programming (ICSP )

Appendix D: Source Codes. PDF created with pdffactory Pro trial version

EECE.3170: Microprocessor Systems Design I Spring 2016

Wireless Model Rocket Igniter, William Grill, Riverhead Systems

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

EXPERIMENT 4: Parallel Input/Output. Objectives Introduction to the Parallel Input/Output (I/O) Familiarization to Interfacing

Bright Idea Light Timer, Junior

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

MPASM 5.46 AT89C2051_PROGRAMMER.ASM :21:50 PAGE 1 VALUE

Introduction to PIC Programming

Experiment 7:The USART


PIC16C63A/65B/73B/74B

Embedded System Design

Embedded Systems Programming and Architectures

Chapter 11: Interrupt On Change

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

Tutorial for PICMON18 Debug Monitor

AN530. Interfacing 93CX6 Serial EEPROMs to PIC16C5X Microcontrollers INTRODUCTION THE HARDWARE CONNECTION THE SOFTWARE CONNECTION

Programmable Lights. Each Line In and Line Out terminal must have its own grounding terminal.

Transcription:

********************************************************************** This file is a basic code template for assembly code generation * on the PICmicro PIC12C508. This file contains the basic code * building blocks to build upon. * If the internal RC oscillator is not implemented then the first * instruction after the ORG 0x000 directive is not required. * Refer to the MPASM User's Guide for additional information on * features of the assembler (Document DS33014). * Refer to the respective PICmicro data sheet for additional * information on the instruction set. * Template file assembled with MPASM V2.11.01 * ********************************************************************** Filename: door.asm * Date: * File Version: * Author: el@jap.hu * Company: http://jap.hu/electronic/ * ********************************************************************** Files required: * ********************************************************************** Notes: * ********************************************************************** #3 veglegesnek szant valtozat, setup moddal digitek: doortime XX delaytime XX hexa, tizedmasodpercben #define F84 #define C508 #ifdef C508 list p=12c508 list directive to define processor #include <p12c508.inc> processor specific variable definitions CONFIG _CP_OFF & _WDT_OFF & _MCLRE_OFF & _IntRC_OSC ' CONFIG' directive is used to embed configuration word within.asm file. The lables following the directive are located in the respective.inc file. See respective data sheet for additional information on configuration word. 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 d @ l i v e. c o m Page 1

#ifdef F84 list p=16f84 list directive to define processor #include <p16f84.inc> processor specific variable definitions CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _HS_OSC ' CONFIG' directive is used to embed configuration data within.asm file. The lables following the directive are located in the respective.inc file. See respective data sheet for additional information on configuration word. ***** VARIABLE DEFINITIONS #ifdef C508 freemem EQU 0x07 #ifdef F84 freemem EQU 0x100x0c temp EQU freemem+0x00 button EQU freemem+0x01 prevbut EQU freemem+0x02 btcnt EQU freemem+0x03 button counter doorcnt EQU freemem+0x04 relay ON counter delaycnt EQU freemem+0x05 delay before door open counter dlcnt0 EQU freemem+0x06 delay sub counter 0 dlcnt1 EQU freemem+0x07 delay sub counter 1 ringer EQU freemem+0x08 prevring EQU freemem+0x09 ringcnt EQU freemem+0x0a switch EQU freemem+0x0b ledcnt EQU freemem+0x0c iobuf EQU freemem+0x0d IOPORT buffer ledpwm EQU freemem+0x0e ledstate1 EQU freemem+0x0f ledstate2 EQU freemem+0x10 ledtemp1 EQU freemem+0x11 ledtemp2 EQU freemem+0x12 flashdir EQU freemem+0x13 flash direction doortime EQU freemem+0x14 door open time delaytime EQU freemem+0x15 delay time prevsw EQU freemem+0x16 previous state of switch ***** I/O structure my F84 testpanel properties RB0 testled DB25/16 OUT RB1 testled DB25/4 OUT RB2 testled RB3 DB25/15 IN RA2 serial OUT RA4 DB25/13 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 d @ l i v e. c o m Page 2

GP0 O RED LED GP1 I BUTTON GP2 O GREEN LED GP3 I SWITCH GP4 I RINGER GP5 O RELAY CTL #ifdef C508 IOPORT EQU GPIO #ifdef F84 IOPORT EQU PORTB #ifdef C508 ********************************************************************** ORG 0x1FF processor reset vector Internal RC calibration value is placed at location 0x1FF by Microchip as a movlw kk, where the kk is a literal value. ORG 0x000 coding begins here movwf OSCCAL update register with factory cal value clrf GPIO movlw 0x1a tris GPIO GP4, GP3, GP1 input movlw 0x80 option wakeup DIS, pullup EN take care of other internal hardware here remaining code goes here #ifdef F84 clrf PORTB clrf PORTA movlw 0x1a tris PORTB movlw 0xff tris PORTA not used movlw 0 pullup EN option LED_GRN EQU 0x31 LED_YEL EQU 0x18 LED_RED EQU 0x00 cold movlw.30 movwf doortime movlw.200 movwf delaytime 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 d @ l i v e. c o m Page 3

warm reset test green led ON clrf iobuf movlw 4 movwf ledstate1 movlw 1 movwf ledstate2 movlw LED_RED movlw 5 movwf temp test0 call delay decfsz temp goto test0 green+red led ON movlw LED_YEL movlw 5 movwf temp test1 call delay decfsz temp goto test1 clrf IOPORT reset test end YEL init variables clrf clrf clrf clrf btcnt doorcnt delaycnt ringcnt clrf button clrf ringer movlw 5 movwf flashdir main cycle cycle call delay clrf iobuf movf button,w movwf prevbut movf IOPORT,W andlw 2 movwf button store button status movf ringer,w movwf prevring movf IOPORT,W andlw 0x10 movwf ringer store ringer status 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 d @ l i v e. c o m Page 4

movf IOPORT,W andlw 8 movwf switch auto switch status call call button_sub door_sub btfsc switch,3 no ringercheck if switch is OFF call ringer_sub call led_sub movf iobuf,w movwf IOPORT call setup_sub optional setup for timers goto cycle delay movf iobuf,w iorwf ledstate1,w movwf ledtemp1 movf iobuf,w iorwf ledstate2,w movwf ledtemp2 movlw.250 movwf dlcnt1 delay1 movlw 0x30 movwf dlcnt0 delay2 movf ledpwm,w subwf dlcnt0,w movf ledtemp1,w btfsc STATUS, C movf ledtemp2,w movwf IOPORT decfsz dlcnt0 goto delay2 decfsz dlcnt1 goto delay1 bcf IOPORT, 2 button_sub movf xorwf bz button,w prevbut,w bt_unchanged button status changed btfss button,1 test button status goto bt_release button release button pressed, reset counter 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 d @ l i v e. c o m Page 5

clrf btcnt bt_unchanged btfsc button,1 test button status incf btcnt measure pressing time bt_release if the button is just released movlw 5 subwf btcnt,w check pressing time clrf btcnt bc bt_long less than half second, immediate ON relay but only if not already in progress movf doorcnt,w bnz bt_skip clrf delaycnt clear delays movf doortime,w movwf doorcnt set relay ON time bsf iobuf, 5 bt_skip bt_long movf delaytime,w set delay time movwf delaycnt door_sub delay movf delaycnt,w bz dr_nodelay delay is counting decfsz delaycnt goto dr_nodelay reached zero movf doortime,w movwf doorcnt bsf iobuf, 5 dr_nodelay door movf doorcnt,w bz dr_nodoor btfss STATUS, Z set relay ON time decf doorcnt dr_nodoor set relay movf doorcnt,w btfss STATUS, Z bz dr_off 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 d @ l i v e. c o m Page 6

bsf iobuf, 5 relay ON dr_off bcf iobuf, 5 relay OFF ringer_sub check if the status changed movf ringer,w xorwf prevring,w bz rg_unchanged ringer status changed btfss ringer,4 test status goto rg_release release ringer pressed, reset counter clrf ringcnt rg_unchanged btfsc ringer,4 test button status incf ringcnt measure pressing time rg_release if the ringer is just released movlw 4 subwf ringcnt,w check pressing time bnc rg_skip long enough ringing, open door movf doortime,w movwf doorcnt set relay ON time rg_skip led_sub movf delaycnt,w iorwf doorcnt,w idle? bnz led_notidle RED in idle or flashing in auto idle movf switch,w bnz led_flash clrf ledpwm RED led_notidle indicate YEL in delay or GRN in opening mode movf doorcnt,w bnz led_door delay mode movlw LED_YEL YEL 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 d @ l i v e. c o m Page 7

led_doordoor opening mode movlw LED_GRN GRN led_flash flash in auto idle mode movf flashdir,w addwf ledpwm,w andlw 0xe0 overflow to the upper 3 bits? btfss STATUS, Z comf flashdir,f negate direction movf flashdir,w addwf ledpwm,f setup_sub call setup0 movf switch,w movwf prevsw setup0 optional setup for timers btfss button,1 test button status check if pressed button is pressed movf switch,w xorwf prevsw,w btfsc STATUS, Z check if the switch state changed switch state changed, enter setup mode clrf iobuf immediate OFF door relay clrf ledstate2 clrf ledpwm setup1 call delay btfsc IOPORT, 1 wait for button release goto setup1 incf ledstate2 set RED LED color call readbyte movf temp,w movwf doortime call readbyte movf temp,w movwf delaytime goto warm readbyte 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 d @ l i v e. c o m Page 8

clrf temp nop BUG!! call read1 first 4 bits, then second half nop BUG!! swapf temp,f read1 clrf btcnt read0 call delay incf btcnt movlw.20 subwf btcnt,w bc read_timeout timeout=2 seconds btfss IOPORT, 1 wait for button press goto read0 button pressed incf temp increase value read2 call delay btfsc IOPORT, 1 wait for button release goto read2 goto read1 read_timeout movlw LED_GRN call delay call delay clrf ledpwm indicate timeout nop BUG!! PATCH for the STACKOFL bug (only 12c508) swapf temp,f read1b clrf btcnt read0b call delay incf btcnt movlw.20 timeout=2 seconds subwf btcnt,w bc read_timeout_b btfss IOPORT, 1 wait for button press goto read0b button pressed incf temp increase value read2b call delay btfsc IOPORT, 1 wait for button release goto read2b goto read1b read_timeout_b movlw LED_GRN call delay call delay indicate timeout 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 d @ l i v e. c o m Page 9

clrf ledpwm PATCH for the STACKOFL bug (only 12c508) end directive 'end of program' 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 d @ l i v e. c o m Page 10