




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
In this cs140 lab, students will learn how to write a program for the pic microcontroller development board to generate and display the logical and, or, and xor of two random numbers. An overview of the lab, functional specification, designing the first piece of code, and programming hints.
Typology: Slides
1 / 8
This page cannot be seen from the preview
Don't miss anything!
In Lab01, 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 will have one very specific task.
Write a program with the following characteristics:
This program is pretty simple really. You could write it in java in about 5 minutes. But it will take MUCH MORE code in PIC Assembler, and will have lots of new learning involved. It’s frequently difficult to do numerous tasks at the same time and that is the case here; you’re coping with a new language, a new piece of hardware and a new IDE.
Your design can be on paper or electronic. It should include boxes that represent methods/subroutines that will be performed by your code. Each box should have the name of the routine, as well as the tasks to be performed by that routine.
I’ve started a design on the next slide to show what I mean.
I’m REALLY emphasizing using separate methods/subroutines for various actions as a way of organizing your thinking.
Start
MainLoop
Smile Frown Be Happy MegaDelay
Delay
This says: Start calls MainLoop: MainLoop in turn calls these various routines – perhaps not every time around the loop, but calls to all these other routines might occur at some time.
The box contains a list of the actions the routine performs.
Random Number Generation: The easiest way to do this is have the program running in a loop. Every time it goes thru the loop it increments a counter. It also checks if the switch has been pushed. When it sees a push, then the counter at that time is the random number to use. This actually is quite random since it depends on a human (who knows nothing about how fast the counter is going) pushing a button at an arbitrary moment.
Code Formatting and Commenting: Formatting is mostly about indentation. I don’t care what you do as long as you’re consistent. Also be consistent about using upper or lower case for mnemonics. Commenting should give the “big picture” of what’s happening. A comment like “moving from accumulator to file” is NOT very useful – that’s what the instruction already tells us. But if you say “Moving accumulator to PORTC to display on lights”, that tells why the instruction is there.
Timers: The spec asks that you keep values in the LEDs for 5 seconds. You will need to develop a timer to do this. I’d recommend that you use the timer already developed in Lab01, and call it repeatedly many times in order to achieve the total time desired.