assignment: lab #6 raspberry pi and intel 8051 assembly ...users.etown.edu/w/wunderjt/333_lab_6_2017...

8
Assignment: LAB #6 Raspberry Pi and Intel 8051 Assembly Language COURSE: EGR/CS333 “DIGITAL DESIGN & INTERFACING” (Digital Design II, Assembly Language, and Interfacing) SYLLABUS: http://users.etown.edu/w/wunderjt/syllabi/CS333%20Wunderlich,Joseph.htm INSTRUCTOR: J. Wunderlich PhD LATE PENALTY: Minus 33.3% per class period for each late item LAST REVISED: 4/8/17 PRE-LAB : 80x51 Customized Simulator Manual(s): http://users.etown.edu/w/wunderjt/home_Lab_Manuals.html DURING LAB : 1. INDIVIDUALLY, Do Raspberry Pi Lab 2” programming as shown below (your first Raspberry Pi Lab 1has been appended to the Lab 5 assignment and can also be found online in the customized user manual for the Raspberry Pi: http://users.etown.edu/w/wunderjt/home_Lab_Manuals.html) 2. AS A GROUP, Simulate an Intel 8051 program: a. Store constants 1,2,4, and 8 into four registers in register bank 0 b. Add them all together and put the result in a fifth register c. Push the fifth register’s contents onto the stack d. Change the PSW so that register bank 1 is used e. Store the constants 16,32,64, and 128 into four registers in register bank 1 f. Add them all together and put the result in a fifth register g. Push the fifth register’s contents onto the stack h. Change the PSW so that register bank 2 is used i. Pop the first sum off of the stack and put it into a Register j. Pop the second sum off of the stack and put into another Register k. Add the contents of these registers and put the result in a RAM Memory location of your choosing, but not overwriting the stack or any of the register banks. l. Add one to the contents of the sum of the above step and watch the carry out bit change in the PSW m. Take screen shots of the memory map to show memory, registers, the stack, and PSW contents changing and put these in your report along with narrative explaining what’s happening, and arrows pointing to changing parts of the memory map. You don’t need a screen shot for every step above, but several screen shots at select steps should suffice. GRADING : For both demonstrations and reports, a 92 is for everything done very well and professional. To get up to 100 or more, enhance things in creative ways GRADE PERCENTAGES and DUE DATES: Demonstrate PAD-234 Circuit Trainer circuits [primarily for 5 volt TTL chips] Demonstrate Old Circuit Trainer circuits [primarily for 5 volt TTL chips]: Demonstrate RadioShack Circuit Trainer circuits [primarily for ~3 volt CMOS chips]: Demonstrate Logisim Circuit simulations Demonstrate Phoenix Contact NanoLC PLC simulations Demonstrate Phoenix Contact NanoLC PLC real-time systems Demonstrate Phoenix Contact IEC-61131 PLC simulations: Demonstrate Phoenix Contact IEC-61131 PLC real-time systems: Demonstrate Field Programmable Gate Array (FPGA) simulations: Demonstrate Field Programmable Gate Array (FPGA) real-time systems: Demonstrate INTEL 8051/80251 or ARM microcontroller simulations: (25%) FRIDAY 4/21/17 AT 3:30PM Demonstrate INTEL 8051/80251 or ARM microcontroller real-time systems: Demonstrate Raspberry Pi real-time systems (50%) FRIDAY 4/21/17 AT 3:30PM TEAM MEMBER NAME________________________ Grade: TEAM MEMBER NAME________________________ Grade: TEAM MEMBER NAME________________________ Grade: Demonstrate Arduino real-time systems: Demonstrate Basic-Stamp real-time systems: Demonstrate Direct PC-port real-time systems: Demonstrate Remote mobile-device real-time systems: Demonstrate LabView real-time systems: Demonstrate Isolated high-voltage bench-test (with low Voltage electronics disconnected) Demonstrate Other: Written Group Report (including all individual Raspberry Pi work): (25%) FRIDAY 4/21/17 AT 3:30PM PowerPoint, Video, or Poster

Upload: others

Post on 05-Jan-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Assignment: LAB #6 Raspberry Pi and Intel 8051 Assembly ...users.etown.edu/w/wunderjt/333_Lab_6_2017 Clarified 4_8_17.pdf · Raspberry Pi and Intel 8051 Assembly Language COURSE:

Assignment: LAB #6

Raspberry Pi and Intel 8051 Assembly Language

COURSE: EGR/CS333 “DIGITAL DESIGN & INTERFACING” (Digital Design II, Assembly Language, and Interfacing) SYLLABUS: http://users.etown.edu/w/wunderjt/syllabi/CS333%20Wunderlich,Joseph.htm

INSTRUCTOR: J. Wunderlich PhD

LATE PENALTY: Minus 33.3% per class period for each late item

LAST REVISED: 4/8/17 PRE-LAB: 80x51 Customized Simulator Manual(s): http://users.etown.edu/w/wunderjt/home_Lab_Manuals.html DURING LAB:

1. INDIVIDUALLY, Do “Raspberry Pi Lab 2” programming as shown below (your first “Raspberry Pi Lab 1” has been appended to the Lab

5 assignment and can also be found online in the customized user manual for the Raspberry Pi: http://users.etown.edu/w/wunderjt/home_Lab_Manuals.html)

2. AS A GROUP, Simulate an Intel 8051 program:

a. Store constants 1,2,4, and 8 into four registers in register bank 0 b. Add them all together and put the result in a fifth register c. Push the fifth register’s contents onto the stack d. Change the PSW so that register bank 1 is used e. Store the constants 16,32,64, and 128 into four registers in register bank 1 f. Add them all together and put the result in a fifth register g. Push the fifth register’s contents onto the stack h. Change the PSW so that register bank 2 is used i. Pop the first sum off of the stack and put it into a Register j. Pop the second sum off of the stack and put into another Register k. Add the contents of these registers and put the result in a RAM Memory location of your choosing, but not overwriting

the stack or any of the register banks. l. Add one to the contents of the sum of the above step and watch the carry out bit change in the PSW m. Take screen shots of the memory map to show memory, registers, the stack, and PSW contents changing and put

these in your report along with narrative explaining what’s happening, and arrows pointing to changing parts of the memory map. You don’t need a screen shot for every step above, but several screen shots at select steps should suffice.

GRADING: For both demonstrations and reports, a 92 is for everything done very well and professional. To get up to 100 or more, enhance things in creative ways

GRADE PERCENTAGES and DUE DATES:

Demonstrate PAD-234 Circuit Trainer circuits [primarily for 5 volt TTL chips] Demonstrate Old Circuit Trainer circuits [primarily for 5 volt TTL chips]: Demonstrate RadioShack Circuit Trainer circuits [primarily for ~3 volt CMOS chips]: Demonstrate Logisim Circuit simulations Demonstrate Phoenix Contact NanoLC PLC simulations Demonstrate Phoenix Contact NanoLC PLC real-time systems

Demonstrate Phoenix Contact IEC-61131 PLC simulations:

Demonstrate Phoenix Contact IEC-61131 PLC real-time systems: Demonstrate Field Programmable Gate Array (FPGA) simulations:

Demonstrate Field Programmable Gate Array (FPGA) real-time systems: Demonstrate INTEL 8051/80251 or ARM microcontroller simulations: (25%) FRIDAY 4/21/17 AT 3:30PM

Demonstrate INTEL 8051/80251 or ARM microcontroller real-time systems:

Demonstrate Raspberry Pi real-time systems (50%) FRIDAY 4/21/17 AT 3:30PM

TEAM MEMBER NAME________________________ Grade: TEAM MEMBER NAME________________________ Grade: TEAM MEMBER NAME________________________ Grade:

Demonstrate Arduino real-time systems:

Demonstrate Basic-Stamp real-time systems:

Demonstrate Direct PC-port real-time systems:

Demonstrate Remote mobile-device real-time systems:

Demonstrate LabView real-time systems:

Demonstrate Isolated high-voltage bench-test (with low Voltage electronics disconnected)

Demonstrate Other:

Written Group Report (including all individual Raspberry Pi work): (25%) FRIDAY 4/21/17 AT 3:30PM

PowerPoint, Video, or Poster

Page 2: Assignment: LAB #6 Raspberry Pi and Intel 8051 Assembly ...users.etown.edu/w/wunderjt/333_Lab_6_2017 Clarified 4_8_17.pdf · Raspberry Pi and Intel 8051 Assembly Language COURSE:

Elizabethtown College CS333 – Spring 2017 Raspberry Pi Lab #2 – A/D Photoresistor By Daniel Esteves & Joseph Wunderlich PhD 1- Introduction Also known as light-dependent resistor(LDR), the photoresistor ajusts its resistance according to the light received from the environment. It works not only with sunlight, but also with artificial light. Now lets see how we can integrate it to the real world.

2- The Raspberry Pi(RPi) With your RPi turned on, make sure it is connected to the internet by going to the Internet Browser and trying to access google.com( don’t try to access etown.edu since the college authorizes this communication even though you are not actually connected to the internet). If you got the connection, open Terminal

3- The Terminal

• sudo apt-get update

• sudo apt-get upgrade ALWAYS do this before messing with Terminal. It updates the libraries and commands.

This shouldn't take much time, but expect it to be a time consuming process in the future, since more libraries, more time to check all. For this Lab, we will be using WiringPi to run a C script. It works pretty much like rpi.gpio, from the last lab, but uses C.

Page 3: Assignment: LAB #6 Raspberry Pi and Intel 8051 Assembly ...users.etown.edu/w/wunderjt/333_Lab_6_2017 Clarified 4_8_17.pdf · Raspberry Pi and Intel 8051 Assembly Language COURSE:

4.1- The Hardware Setup You should connect the project as the picture below:

The IC is a A/D adapter(MCP3204) and the resistor a 10K Ohm. Use the website https://pinout.xyz/ to find out the pin names so you can connect to the right place.

MCP3204 schematics

Page 4: Assignment: LAB #6 Raspberry Pi and Intel 8051 Assembly ...users.etown.edu/w/wunderjt/333_Lab_6_2017 Clarified 4_8_17.pdf · Raspberry Pi and Intel 8051 Assembly Language COURSE:

4.2- The Software Setup Lets start by installing GIT: sudo apt-get install git-core

If you are wondering what is GIT, it is a version control system to track changes on your files and

computer. Here is the link to the creators website: https://git-scm.com

After downloading GIT, you will be able to get WiringPi using this command:

git clone git://git.drogon.net/wiringPi

To build WiringPi cd wiringPi

./build

Now lets create the Script by entering: sudo touch res.c

sudo nano res.c

After you enter this command, nano will prompt so you can edit res.c.

For this exemple, the code used can be seen below:

#include <stdio.h>

#include <string.h>

#include <errno.h>

#include <stdlib.h>

#include <unistd.h>

#include <wiringPi.h>

#include <wiringPiSPI.h>

#include <unistd.h>

Page 5: Assignment: LAB #6 Raspberry Pi and Intel 8051 Assembly ...users.etown.edu/w/wunderjt/333_Lab_6_2017 Clarified 4_8_17.pdf · Raspberry Pi and Intel 8051 Assembly Language COURSE:

#define CS_MCP3208 8 // BCM_GPIO8

#define SPI_CHANNEL 0

#define SPI_SPEED 100000 //

int read_mcp3208_adc(unsigned char adcChannel)

{

unsigned char buff[3];

int adcValue = 0;

buff[0] = 0x06 | ((adcChannel & 0x07) >> 7);

buff[1] = ((adcChannel & 0x07) << 6);

buff[2] = 0x00;

digitalWrite(CS_MCP3208, 0); // Low : CS Active

wiringPiSPIDataRW(SPI_CHANNEL, buff, 3);

buff[1] = 0x0F & buff[1];

adcValue = ( buff[1] << 8) | buff[2];

digitalWrite(CS_MCP3208, 1); // High : CS Inactive

return adcValue;

}

int main (void)

{

int adc1Channel = 0;

Page 6: Assignment: LAB #6 Raspberry Pi and Intel 8051 Assembly ...users.etown.edu/w/wunderjt/333_Lab_6_2017 Clarified 4_8_17.pdf · Raspberry Pi and Intel 8051 Assembly Language COURSE:

int adc1Value = 0;

if(wiringPiSetup() == -1)

{

fprintf (stdout, "Unable to start wiringPi: %s\n", strerror(errno));

return 1 ;

}

if(wiringPiSPISetup(SPI_CHANNEL, SPI_SPEED) == -1)

{

fprintf (stdout, "wiringPiSPISetup Failed: %s\n", strerror(errno));

return 1 ;

}

pinMode(CS_MCP3208, OUTPUT);

while(1)

{

system("clear");

printf("\n\nMCP3208 channel output.\n\n");

adc1Value = read_mcp3208_adc(adc1Channel);

printf("adc0 Value = %04u", adc1Value);

printf("\tVoltage = %.3f\n", ((3.3/4096) * adc1Value));

usleep(1000000);

}

return 0;

}

To Exit nano, press Ctrl+X, it will ask if you are sure, Press “Y” and Enter for the res.c name. Compile the code by entering gcc -Wall -o app res.c -lwiringPi

Page 7: Assignment: LAB #6 Raspberry Pi and Intel 8051 Assembly ...users.etown.edu/w/wunderjt/333_Lab_6_2017 Clarified 4_8_17.pdf · Raspberry Pi and Intel 8051 Assembly Language COURSE:

Run the code with this command sudo ./app

It should display this screen

5- Now you! 1- Check the res.c file. Make the promp, instead of displaying “MCP3208 channel output.”, display “Lab 2 – Student name” on the prompt screen. Also, before each line of “adc0 Value = …” display the counting number. The output should be something like that: “Lab 2 – Daniel Esteves 1 – Voltage = 2.224” 2- Using the same res.c file, instead of showing values, trigger a LED to turn on if the voltage is lower or equal to 2V. This will require a little more work and you may want to check out this page( https://projects.drogon.net/raspberry-pi/wiringpi/functions/ ). You can also make something else, other than trigger a LED, but check out with the TA or Dr. Wunderlich beforehand to see if it is ok.

Page 8: Assignment: LAB #6 Raspberry Pi and Intel 8051 Assembly ...users.etown.edu/w/wunderjt/333_Lab_6_2017 Clarified 4_8_17.pdf · Raspberry Pi and Intel 8051 Assembly Language COURSE:

RULES FOR ALL LABS

(always include this too in each lab report)

IF LABS ARE BUILT (AND POSSIBLY REBUILT), BUT DON'T FULLY FUNCTION: For demonstrations and reports, deduct depends on how adequately you identify problems. For example, make test set-ups to verify functionality of isolated chips, circuit trainer elements, software, relays, other electronics, motors or other higher-voltage circuits and devices. PROVE THAT NO EASY FIX OR SUBSTITUTION WAS POSSIBLE or EASILY IDENTIFIABLE AT THE TIME. Discuss (1) How you identified problems, and (2) How you tried to fix them. Include evidence that you fully understand and have properly connected all pins on a given chip (including considering floating-pins, powering the chip, needed pull-up resistors, proper voltage levels, etc.), and that you have exhausted much time attempted to solve all problems). INCLUDE PHOTO’S OF ALL CIRCUITS (AND TEST-SET-UP’S) BUILT

REPORTS must include: Title Page with lab number, name of lab, your names, Majors, Year (e.g., Junior), who is demonstrating, and who is the designated TEAM LEADER

Sections numbered and tilted as follows (always list all of these, and simply put “NA” if not applicable): 1. “Assignment” (An exact copy of everything in this document -- exactly how it looks here) 2. “Equipment Used” (A list of hardware and software) INCLUDE PHOTO’S OF ALL EQUIPMENT 3. “Methodology” (including all design steps, analysis, DECISIONS MADE, etc.) INCLUDE PHOTO’S OF ALL CIRCUITS BUILT 4. “Options” (if applicable, a comparison of each method used) 5. “Problems Encountered” (including any debugging methodology) INCLUDE PHOTO’S OF ANY TEST-CIRCUITS BUILT 6. “Testing Methodology” (including timing traces, test-vectors, and RATIONALE FOR HOW YOUR METHODOLOGY ASSURES QUALITY COVERAGE including estimated probability of satisfactory coverage by chosen test vectors 7. “References” (in standard IEEE format) 8. “Appendices” (for spec sheets, etc.)

ALL DESIGN PROCESS STEPS MUST BE INCLUDED for Digital Logic designs (NUMBERED as in EGR/CS 332). If design step not done, list as “N.A.” For Combinational Digital Logic Design: Step 1: Define problem, Step 2: Encode variables, Step 3: Create truth table, Step 4: Find simplified function(s), Step 5: Draw logic circuit, Step 6: Convert to NAND’s, Step 7: Check assumptions, Step 8: Chip circuit diagram For Sequential Digital Logic Design::Step 1: Define problem, Step 2: Create state diagram, Step 3: Encode variables, Step 4: Minimize machine, Step 5: Create state table, Step 6: Append flip-flop inputs, Step 7: Find simplified function(s), Step 8: Draw logic circuit, Step 9: Convert to NAND’s Step 10: Analyze any unused states, Step 11: Revise state diagram, Step 12: Check Assumptions, Step 13: Chip circuit diagram

COLOR-CODED LOGIC DIAGRAMS are required for any digital circuit (Breadboard, FPGA, etc.)

COLOR-CODED CIRCUIT SCHEMATICS are required for any circuit implemented (Breadboard, PLC, ladder logic, etc.), color is a must, hand-colored is ok

FLOW CHART is required for any program

COMMENT EVERY LINE OF CODE

TEAM LEADER has responsibility of coordinating all equipment problems with the Teaching Assistant. Try to stick with same person for this role.

TEACHING ASSISTANT will guarantee all working hardware and software when needed and will facilitate acquisition of needed parts.