Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Determine Frequency - Assembler Programming and Computer Organization - Lecture Slides, Slides of Computer Architecture and Organization

The Assembler Programming and Computer Organization, is very helpful series of lecture slides, which made programming an easy task. The major points in these laboratory assignment are:Determine Frequency, Development Board, Write Code, Hardware Specification, Assembly Instructions, Frequency of Oscillator, Oscillator Description, Interrupt Handler, Debug Board, Timer for Rotation

Typology: Slides

2012/2013

Uploaded on 04/24/2013

baijayanthi
baijayanthi 🇮🇳

4.5

(13)

171 documents

1 / 9

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS140 - Lab04 1
Computer Organization
CS 140
Programming The PIC
Micro Controller
Docsity.com
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Determine Frequency - Assembler Programming and Computer Organization - Lecture Slides and more Slides Computer Architecture and Organization in PDF only on Docsity!

CS140 - Lab04 1

Computer Organization

CS 140

Programming The PIC

Micro Controller

CS140 - Lab04 2

In Lab 01, you learned how to program the PIC Microcontroller running on the

Development Board. You could write a bit of new code, and you could explain

what various Assembly instructions do. You also had a general idea of how to

read the hardware specification. In this lab you combine those skills,

programming the PIC microcontroller to use its various hardware features.

In this lab, you will have three very specific tasks.

1. Starting with code given to you, determine the frequency at which the 16F

is running.

2. Modify or write code to handle an interrupt from the switch on the Development

Board.

3. Modified or write code that allows you to store data in the EEPROM of the

16F886.

The Lab - Overview

CS140 - Lab04 4

Task 2: Write your own Interrupt Handler

In the previous lab, you’ve seen a number of programs that employ the

switch, the interrupt handler, the timer for rotation, etc. Your goal in this Task is to use these components in a new way. Here’s what your program Task2.asm should do.

Using the Debug Board, the switch must cause an interrupt. The switch

toggles between two LED actions – an “all flash” mode in which all four LEDs are alternately on/off and a “rotate” mode similar to that in 03_Rotate.asm. The Pot does not need to be used unless you wish to. The frequency of flash/rotate can be constant.

You can wire the switch to any pin on the PIC that you wish.

.

CS140 - Lab04 5

Task 2: Write your own Interrupt Handler

Helpful hints:

1. When I wrote this code, I tried to start with an existing program and rip it apart.

This produced a very tangled program. I recommend you start from scratch

using previous code as examples.

2. Your code will have various sections:

  • Start – sets up the registers to enable interrupts and make LEDs outputs
  • Delay – a subroutine as we’ve used before.
  • Interrupt Service Routine – hardware control goes here when switch

changes state ( high  low or low  high. ) This routine can set the

flash/rotate flag.

  • Main Loop – checks for flash/rotate modes and produces LED action.

3. You will need to program various registers to get the switch interrupt to work.

Look at:

TRIS register to control if a pin is input or output.

IOCB register to specify interrupt on change

INTCON register to turn on interrupts

4. I found the Microchip document AN552 to be helpful – you can search on their

website.

CS140 - Lab04 7

Task 3: Write an EEPROM Reader/Writer

The code given in the 16F886 spec doesn’t really work. Here’s some modified code that seems OK.

#define XX ; Your choice of locations ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; This code is modified from that in the 16F886 Manual, Section 10.1. ; Enter: ; You must previoiusly have a #define that specifies the EEProm ; address where the data should be written. Here it's written ; as DATA_EE_ADDR ; Exit: ; W contains the value read from EEProm ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; EEProm_Read: BANKSEL EEADR ; movlw DATA_EE_ADDR ; Address we're using in EEProm movwf EEADR ; Data Memory Address to read BANKSEL EECON1 ; bcf EECON1, EEPGD ; Specify using EEProm data memory bsf EECON1, RD ; Set RD bit to begin reading BANKSEL EEDAT movf EEDAT, W ; W = EEDAT BANKSEL STATUS ; Bank 0 return

CS140 - Lab04 8

Task 3: Write an EEPROM Reader/Writer

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; This code is modified from that in the 16F886 Manual, Section 10.1. ; Enter: ; On entry, W contains the value to be written ; You must previoiusly have a #define that specifies the EEProm ; address where the data should be written. ; Exit: ; No values are returned. Bank is restored to 0. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; EEProm_Write: BANKSEL EEADR ; movwf EEDATA ; Data Memory Value to write movlw DATA_EE_ADDR movwf EEADR ; Data Memory Address to write BANKSEL EECON bcf EECON1, EEPGD ; Specify using EEProm data memory bsf EECON1, WREN ; Enable writes movlw 55h ; Simply because the formula says to do this movwf EECON2 ; Write 55h to virtual address movlw 0xAA ; movwf EECON2 ; Write AAh bsf EECON1, WR ;Set WR bit to begin write EEProm_Loop: btfsc EECON1, WR ; When bit is clear, write has finished goto EEProm_Loop bcf EECON1, WREN ;Disable writes BANKSEL 0x00 ;Bank 0 -return to normal return Docsity.com