Arduino Nano Embedded Controller USB cable to connect to laptop Protoboard with
ID: 2085889 • Letter: A
Question
Arduino Nano Embedded Controller USB cable to connect to laptop Protoboard with cables 4 LEDs with resistors or 7-segment display 1 Servo 1 analog PSD sensor Control a Servo Actuator from an Analog Sensor Write an Assembly program that will output a repetitive rectangle signal as below with 1ms high and 19ms low. Display the generated curve on an oscilloscope: there should be a stable signal. Then connect a servo to the output line. It should drive to a fixed location. Connect an analog PSD sensor to the Nano controller. Write an Assembly program to continuously read its value. Transform the input data range [0..255] to a 4-bit number and display it using 4 LEDs or 7-seg. display on an output port. (For testing, you can also write back the values via the USB link to your laptop). Combine the two previous experiments as follows: In a continuous loop, read the PSD sensor value, then set the servo output accordingly. Vary servo up-time output in range 1.0-2.0ms, depending on PSD input. The servo should move to different positions, depending on the PSD sensor's measured distance.Explanation / Answer
/* Serial 7-Segment Display Example Code
Serial Mode Stopwatch
by: Jim Lindblom
SparkFun Electronics
date: November 27, 2012
license: This code is public domain.
This example code shows how you could use software serial
Arduino library to interface with a Serial 7-Segment Display.
There are example functions for setting the display's
brightness, decimals and clearing the display.
The print function is used with the SoftwareSerial library
to send display data to the S7S.
Circuit:
Arduino -------------- Serial 7-Segment
5V -------------------- VCC
GND -------------------- GND
8 -------------------- RX
*/
#include <SoftwareSerial.h>
// These are the Arduino pins required to create a software seiral
// instance. We'll actually only use the TX pin.
const int softwareTx = 8;
const int softwareRx = 7;
SoftwareSerial s7s(softwareRx, softwareTx);
unsigned int counter = 0; // This variable will count up to 65k
char tempString[10]; // Will be used with sprintf to create strings
void setup()
{
// Must begin s7s software serial at the correct baud rate.
// The default of the s7s is 9600.
s7s.begin(9600);
// Clear the display, and then turn on all segments and decimals
clearDisplay(); // Clears display, resets cursor
s7s.print("-HI-"); // Displays -HI- on all digits
setDecimals(0b111111); // Turn on all decimals, colon, apos
// Flash brightness values at the beginning
setBrightness(0); // Lowest brightness
delay(1500);
setBrightness(127); // Medium brightness
delay(1500);
setBrightness(255); // High brightness
delay(1500);
// Clear the display before jumping into loop
clearDisplay();
}
void loop()
{
// Magical sprintf creates a string for us to send to the s7s.
// The %4d option creates a 4-digit integer.
sprintf(tempString, "%4d", counter);
// This will output the tempString to the S7S
s7s.print(tempString);
setDecimals(0b00000100); // Sets digit 3 decimal on
counter++; // Increment the counter
delay(100); // This will make the display update at 10Hz.
}
// Send the clear display command (0x76)
// This will clear the display and reset the cursor
void clearDisplay()
{
s7s.write(0x76); // Clear display command
}
// Set the displays brightness. Should receive byte with the value
// to set the brightness to
// dimmest------------->brightest
// 0--------127--------255
void setBrightness(byte value)
{
s7s.write(0x7A); // Set brightness command byte
s7s.write(value); // brightness data byte
}
// Turn on any, none, or all of the decimals.
// The six lowest bits in the decimals parameter sets a decimal
// (or colon, or apostrophe) on or off. A 1 indicates on, 0 off.
// [MSB] (X)(X)(Apos)(Colon)(Digit 4)(Digit 3)(Digit2)(Digit1)
void setDecimals(byte decimals)
{
s7s.write(0x77);
s7s.write(decimals);
}
OR
Program.
ORG 000H //initial starting address
START: MOV A,#00001001B // initial value of accumulator
MOV B,A
MOV R0,#0AH //Register R0 initialized as counter which counts from 10 to 0
LABEL: MOV A,B
INC A
MOV B,A
MOVC A,@A+PC // adds the byte in A to the program counters address
MOV P1,A
ACALL DELAY // calls the delay of the timer
DEC R0//Counter R0 decremented by 1
MOV A,R0 // R0 moved to accumulator to check if it is zero in next instruction.
JZ START //Checks accumulator for zero and jumps to START. Done to check if counting has been finished.
SJMP LABEL
DB 3FH // digit drive pattern for 0
DB 06H // digit drive pattern for 1
DB 5BH // digit drive pattern for 2
DB 4FH // digit drive pattern for 3
DB 66H // digit drive pattern for 4
DB 6DH // digit drive pattern for 5
DB 7DH // digit drive pattern for 6
DB 07H // digit drive pattern for 7
DB 7FH // digit drive pattern for 8
DB 6FH // digit drive pattern for 9
DELAY: MOV R4,#05H // subroutine for delay
WAIT1: MOV R3,#00H
WAIT2: MOV R2,#00H
WAIT3: DJNZ R2,WAIT3
DJNZ R3,WAIT2
DJNZ R4,WAIT1
RET
END
MULTIPLEXING
Program.
ORG 000H // initial starting address
MOV P1,#00000000B // clears port 1
MOV R6,#1H // stores "1"
MOV R7,#6H // stores "6"
MOV P3,#00000000B // clears port 3
MOV DPTR,#LABEL1 // loads the adress of line 29 to DPTR
MAIN: MOV A,R6 // "1" is moved to accumulator
SETB P3.0 // activates 1st display
ACALL DISPLAY // calls the display sub routine for getting the pattern for "1"
MOV P1,A // moves the pattern for "1" into port 1
ACALL DELAY // calls the 1ms delay
CLR P3.0 // deactivates the 1st display
MOV A,R7 // "2" is moved to accumulator
SETB P3.1 // activates 2nd display
ACALL DISPLAY // calls the display sub routine for getting the pattern for "2"
MOV P1,A // moves the pattern for "2" into port 1
ACALL DELAY // calls the 1ms delay
CLR P3.1 // deactivates the 2nd display
SJMP MAIN // jumps back to main and cycle is repeated
DELAY: MOV R3,#02H
DEL1: MOV R2,#0FAH
DEL2: DJNZ R2,DEL2
DJNZ R3,DEL1
RET
DISPLAY: MOVC A,@A+DPTR // adds the byte in A to the address in DPTR and loads A with data present in the resultant address
RET
LABEL1:DB 3FH
DB 06H
DB 5BH
DB 4FH
DB 66H
DB 6DH
DB 7DH
DB 07H
DB 7FH
DB 6FH
END
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.