Application Note - PIC Source Code v1.1.doc

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

Lecture (04) PIC16F84A (3)

D:\PICstuff\PartCounter\PartCounter.asm

16.317: Microprocessor Systems Design I Fall 2013 Exam 3 Solution

PIC 16F84A programming (II)

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

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

Assembly Language Instructions

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

Chapter 4 Sections 1 4, 10 Dr. Iyad Jafar

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

16.317: Microprocessor-Based Systems I Spring 2012

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

CENG 336 INT. TO EMBEDDED SYSTEMS DEVELOPMENT. Spring 2006

16.317: Microprocessor-Based Systems I Summer 2012

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

Flow Charts and Assembler Programs

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

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

APPLICATION NOTE Wire Communication with a Microchip PICmicro Microcontroller

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

Instuction set

SOLUTIONS!! DO NOT DISTRIBUTE!!

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

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

Embedded System Design

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

EEE111A/B Microprocessors

Performance & Applications

Chapter 5 Sections 1 6 Dr. Iyad Jafar

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

ECE Homework #3

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

PIC16F87X 13.0 INSTRUCTION SET SUMMARY INSTRUCTIONS DESCRIPTIONS

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

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

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

ECE Test #1: Name

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

SOLAR TRACKING SYSTEM USING PIC16F84A STEPPER MOTOR AND 555TIMER

DERTS Design Requirements (1): Microcontroller Architecture & Programming

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

Experiment 7:The USART

Week1. EEE305 Microcontroller Key Points

Embedded Systems Programming and Architectures

The University of Texas at Arlington Lecture 5

SOLUTIONS!! DO NOT DISTRIBUTE PRIOR TO EXAM!!

Binary Outputs and Timing

EECE.3170: Microprocessor Systems Design I Summer 2017

EECE.3170: Microprocessor Systems Design I Spring 2016

Chapter 13. PIC Family Microcontroller

Micro II and Embedded Systems

CC0064-SU Custom Controller for up to 64 Sxnnnn with RS232 and USB interfaces User Handbook Version 2.0 CC0064-SU v2.0.odt

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)

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.

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

16.317: Microprocessor Systems Design I Fall 2015

Timer2 Interrupts. NDSU Timer2 Interrupts September 20, Background:

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

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

Arithmetic,logic Instruction and Programs

Chapter 11: Interrupt On Change

CONNECT TO THE PIC. A Simple Development Board

Chapter 3: Further Microcontrollers

which means that writing to a port implies that the port pins are first read, then this value is modified and then written to the port data latch.

Embedded Systems Design (630470) Lecture 4. Memory Organization. Prof. Kasim M. Al-Aubidy Computer Eng. Dept.

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

PIC Discussion. By Eng. Tamar Jomaa

ME 6405 Introduction to Mechatronics

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

Learning Objectives:

Introduction to PIC Programming

16.317: Microprocessor-Based Systems I Fall 2012

Chapter 10 Sections 1,2,9,10 Dr. Iyad Jafar

ME 515 Mechatronics. A microprocessor

Interfacing PIC Microcontrollers to Peripherial Devices

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

EE6008-Microcontroller Based System Design Department Of EEE/ DCE

Four Channel Digital Voltmeter with Display and Keyboard. Four Channel Digital Voltmeter with Display and Keyboard. Hardware

Figure 1: Pushbutton without Pull-up.

C:\IDE\Brooke-16F88-LED\Brooke-16F88_LED.asm

Input/Output Ports and Interfacing

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

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

M PIC16F84A. 18-pinEnhanced FLASH/EEPROM 8-Bit Microcontroller. High Performance RISC CPU Features: Pin Diagrams. Peripheral Features:

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

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

Interrupts. ELEC 330 Digital Systems Engineering Dr. Ron Hayne. Images Courtesy of Ramesh Gaonkar and Delmar Learning

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

16.317: Microprocessor Systems Design I Spring 2015

Introduction to PIC Programming

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

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

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

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

PIC16F84A 7.0 INSTRUCTION SET SUMMARY INSTRUCTIONS DESCRIPTIONS

16.317: Microprocessor Systems Design I Fall Exam 3 December 15, Name: ID #:

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

Introduction. Embedded system functionality aspects. Processing. Storage. Communication. Transformation of data Implemented using processors

Transcription:

Programmable, RGB-backlit LCD Keyswitches APPLICATION NOTE PIC SOURCE CODE 2004-2006 copyright [E³] Engstler Elektronik Entwicklung GmbH. All rights reserved.

PIC Source Code The following Assembler source is taken from our firmware, which is used in our DS00000 DemoBoard prototyping kit. The DemoBoard is operated by a PIC16F627/8. Sample Code, derived from DemoBoard * Filename: Sample source PIC.asm * Date: 13.02.2004 * File Version: First Revision 26.01.2004 * Author: Reinhard Engstler * Company: [E³] Engstler Elektronik Entwicklung GmbH * Files required: p16f628.inc * ************************************************ *************** Notes: actual code snippets not tested * just cut and paste from working demoboard * list p=16f628 list directive to define processor #include p16f628.inc processor specific variable definitions CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _LVP_OFF ' 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. Memory Definitions cblock 0x20 KeyMask PortMask for writing LCD Data SABitCount Bitcounter for LCWrite SABuf transmit buffer for LCD LCParity count '1' bits for parity generation 2 of 8

PortAMask PortBMask Time TimeOut TimeOuth RunCMD wpattern Keyold bcount vtest Colour tmp Pointer:2 RGB:3 endc save point for TRISA save point for TRISB count Time intterupts Count Time intterupts until Power OFF High Byte Count Samples RunCMDes on every Timer IRQ which pattern to be used last key press how many bytes to go general purpose test hand over for Colour value guess what Pointer into Program Memory to read tables 7bit values for RedGreenBlue w_temp equ 0x7E variables used for context saving STATUS_temp equ 0x7F memory always mapped to bank 0 Bit Definitions Defines #DEFINE SA_CLK PORTB,3 LC Clock on RB3 Can't be changed, as PWM is used!!!!!!! for permanent clock tests #DEFINE SA_DATA PORTA Data Lines on RA2, RA3 #DEFINE Key1 02 RA2 handles Data of Key1 #DEFINE Key2 03 RA3 handles Data of Key1 #DEFINE LED_OFF 0x00 #DEFINE Dark_Red #DEFINE Red #DEFINE Bright_Red 0x10 0x20 0x30 3 of 8

#DEFINE Dark_Green #DEFINE Green #DEFINE Bright_Green #DEFINE Dark_Blue #DEFINE Blue #DEFINE Bright_Blue #DEFINE Dark_White #DEFINE White #DEFINE Bright_White #DEFINE SA_CMD_WrDisplay (128, 216, 512 nibbles) #DEFINE SA_CMD_SetColour #DEFINE SA_CMD_EndTr 0x04 0x08 0x0c 0x01 0x02 0x03 0x15 0x2a 0x3f 0x40 Set Adr of Display (3 nibbles) and Bitmap 0x41 Set Colour awaits one param: '00rrggbb' 0x43 end of current command execute ################################################################ ORG 0x000 processor reset vector goto COLD go to beginning of program ORG 0x004 interrupt vector location retfie return from interrupt COLD bcf STATUS,5 set page to 0 (RP0) bcf STATUS,6 (RP1) call InitREG Initialise Register call InitHW Initialise HW ------------------- main movlw 0x0c movwf KeyMask Key1 and Key2 active call WaitKeyReleased Wait for... clrf RunCMD deactivate all flagged functions movlw.32 wait some time 4 of 8

call WAIT to ensure power OK and Keys ready incf Colour, F next Colour call SA_SetColour and show it movlw.32 call WAIT wait some time as last command already send endofcmd bsf KeyMask, Key1 bcf KeyMask, Key2 call SetBitMap6432 call TrBitMap Select Key1 DeSelect Key2 Setup Address Pointer Write Bitmap to Keys goto main ################################################################ GetData movf Pointer,w Get address byte high movwf PCLATH Set Address Byte high to point to Data movf Pointer+1,w get address byte low movwf PCL change Program counter to access data IncPointer incf Pointer+1,f increment address byte low btfsc STATUS,Z do we need to correct address byte high incf Pointer,f if do it return SetBitMap6432 movlw HIGH SA6432 get table address byte high movwf Pointer and set Pointer movlw SA6432 & 0xff get table address byte high movwf Pointer+1 and set Pointer movlw 0x00 set Byte Count for SA6432 movwf bcount return TrBitMap bcf INTCON,7 no Interrupts allowed 5 of 8

in order to ensure proper data transfer movlw SA_CMD_WrDisplay Start WriteDisplay sequence call SAWrite Transmit command movlw 0x00 Addressnibble 0: 0 call SAWrite movlw 0x00 Addressnibble 1: 0 call SAWrite movlw 0x00 Addressnibble 2: 0 call SAWrite Trloop call GetData get data of Bitmap andlw 0x0f as there is still the lower nibble call SAWrite and send to Key call GetData get same byte again andlw 0xf0 only 4 bits allowed per transmit -SA protocol movwf tmp save data swapf tmp,w data has to be in the lower nibble call SAWrite send next nibble of data call IncPointer Point to next Byte of Bitmap decfsz bcount, F Bitmap complete? goto Trloop no - nxt byte bsf INTCON,7 allow Interrupts return ********************************************************* SAWrite ********************************************************* SAWrite write Data = W to SA Key movwf SABuf save Data to be send in SABuf movlw.8 movwf SABitCount set the #bits to 8 bitout btfss SABuf,7 check MSB goto bit_low Skip if Bit was '0' 6 of 8

bsf PORTA, Key1 Set Data Line of selected Key (1/2) high bsf PORTA, Key2 This can be done with both keys even not selected! goto sndbit bit_low btfsc KeyMask, Key1 if Key1 selected bcf PORTA, Key1 send 0-bit to Key1 btfsc KeyMask, Key2 if Key2 selected bcf PORTA, Key2 send 0-bit to Key2 sndbit bcf SA_CLK set clk low data is shifted in now bsf SA_CLK set clk high rlf SABuf, F rotate SABuf right decfsz SABitCount, F 8 bits done? goto bitout no - nxt bit bsf PORTA, Key1 Set Data Line of both Keys high bsf PORTA, Key2 in case of auto clock retlw 0 end If you have additional questions, please contact techsupport@e3-keys.com. 7 of 8

Contact Information [E³] Engstler Elektronik Entwicklung GmbH Industriering 7 63868 Grosswallstadt Germany Phone: +49 (0) 6022 262570 Fax: +49 (0) 6022 262571 E-Mail: info@e3-keys.com 8 of 8