fixed up lab5

This commit is contained in:
RustyRaptor committed 2020-03-08 17:03:28 -06:00
1 parent bf7e2f70e0
commit ce2f2d0605
2 files changed
+150 -276

No files matched your search

+136 -150
View File
@@ -1,159 +1,145 @@
.data
.size segment_table, 4
.size portb_table, 10
.size portd_table, 10
.data
.comm segment, 1
.comm digit, 1
.global segment, digit
.text
.global setup_ports
.global select_segment
.global show_num
setup_ports:
ldi r16, 0b00011111
ldi R17, 0b11111100
out 0x04, r16
out 0x0A, r17
ret
// select the segment
select_segment:
out 0x05, R19
out 0x0B, R19
segment_table: #binary for seting input on PORTB for segment select
.byte 0b00000010, 0b00000100, 0b00001000, 0b00010000
;; 0, 1, 2,3 4, 5, 6 , 7, 8 , 9
portb_table: # list of binary sequences for setting port B to be ORed with segment table ite
.byte 0b00000001,1,0,0,0,0,0,1,0,0
portd_table: # list of binary sequences for setting port D.
.byte 0b00000000,0b11100100,0b10010000,0b11000000,0b01100100,0b01001000,0b00001100,0b11100000,0, 0b01100000
segmentv: .byte 1
.comm segment, 1 ;; the common name for segment
.comm digit, 1 ;; the digit into our sequences
.global segment, digit
# --------
.text
.global setup_ports
.global select_segment
.global display_segment
setup_ports: ;; routine to set the ports into output mode
LDI r16, 0b00011111
LDI R17, 0b11111100
OUT 0x04, r16 ;;PORT B
out 0x0A, R17
;; set PORT B
;; set PORT D
ret ;; of setup_ports
select_segment:;;selects the segment to light up
LDI R19, 0
OUT 0x05, R19
OUT 0x0B, R19
LDS R18, segment
CPI R18, 0 ;;compare the values
BREQ SEGZERO ;;branch to specific function
CPI R18, 1
BREQ SEGONE
CPI R18, 2
BREQ SEGTWO
JMP SEGTHREE
cpi R18, 0
breq SEGMENT0
cpi R18, 1
breq SEGMENT1
cpi R18, 2
breq SEGMENT2
JMP SEGMENT3
SEGZERO: ;;make only the first segment light up
LDI R19, 0b00011100
OUT 0x05, R19
ret;
SEGONE: ;;make only the second segment light up
LDI R19, 0b00011010
OUT 0x05, R19
ret;
SEGTWO: ;;make only the third segment light up
LDI R19, 0b00010110
OUT 0x05, R19
ret;
SEGTHREE: ;;make only the third segment light up
LDI R19, 0b00001110
OUT 0x05, R19
ret;
SEGMENT0:
ldi R19, 0b00011100
out 0x05, R19
ret
SEGMENT1:
ldi R19, 0b00011010
out 0x05, R19
ret
SEGMENT2:
ldi R19, 0b00010110
out 0x05, R19
ret
SEGMENT3:
ldi R19, 0b00001110
out 0x05, R19
ret
// Select the digit.
show_num:
LDS R20, digit
cpi R20, 0
breq SHOW0
cpi R20, 1
breq SHOW1
cpi R20, 2
breq SHOW2
cpi R20, 3
breq SHOW3
cpi R20, 4
breq SHOW4
cpi R20, 5
breq SHOW5
cpi R20, 6
breq SHOW6
cpi R20, 7
breq SHOW7
cpi R20, 8
breq SHOW8
JMP SHOW9
display_segment: ;; main entry point for setting the segment
LDS R20, digit;
CPI R20, 0;
BREQ LIGHT0
CPI R20, 1;
BREQ LIGHT1
CPI R20, 2;
BREQ LIGHT2
CPI R20, 3;
BREQ LIGHT3
CPI R20, 4;
BREQ LIGHT4
CPI R20, 5;
BREQ LIGHT5
CPI R20, 6;
BREQ LIGHT6
CPI R20, 7
BREQ LIGHT7
CPI R20, 8;
BREQ LIGHT8
JMP LIGHT9
LIGHT0:;;lights up 0
LDI R22, 0b11111111
OUT 0x0B, R22
ret;
LIGHT1:;;lights up 1
LDI R22, 0b00011000
OUT 0x0B, R22
ret;
LIGHT2:;;lights up 2
LDI R22, 0b01101100
LDI R23, 0b00000001
ADD R19, R23
OUT 0x05, R19
// Display the correct digit.
SHOW0:
ldi R22, 0b11111111
out 0x0B, R22
ret
LIGHT3:;;lights up 3
LDI R22, 0b00111100
LDI R23, 0b00000001
ADD R19, R23
OUT 0x05, R19
out 0x0B, R22
ret
LIGHT4:;;lights up 4
LDI R22, 0b10011000
LDI R23, 0b00000001
ADD R19, R23
OUT 0x05, R19
out 0x0B, R22
ret
LIGHT5:;;loghts up 5
LDI R22, 0b10110100
LDI R23, 0b00000001
ADD R19, R23
OUT 0x05, R19
out 0x0B, R22
ret
LIGHT6:;;lights up 6
LDI R22, 0b11110100
LDI R23, 0b00000001
ADD R19, R23
OUT 0x05, R19
out 0x0B, R22
ret
LIGHT7:;;lights up 7
LDI R22, 0b00011100
out 0x0B, R22
ret
LIGHT8:;;lights up 8
LDI R22, 0b11111100
LDI R23, 0b00000001
ADD R19, R23
OUT 0x05, R19
out 0x0B, R22
ret
LIGHT9:;;lights up 9
LDI R22, 0b10011100
LDI R23, 0b00000001
ADD R19, R23
OUT 0x05, R19
out 0x0B, R22
ret
;; the goal is the use "digit" to and "segment" to find the values that need
;; to be sent to PORTB and PORT D
SHOW1:
ldi R22, 0b00011000
out 0x0B, R22
ret
ret ;; of display_segment
SHOW2:
ldi R22, 0b01101100
ldi R23, 0b00000001
add R19, R23
out 0x05, R19
out 0x0B, R22
ret
SHOW3:
ldi R22, 0b00111100
ldi R23, 0b00000001
add R19, R23
out 0x05, R19
out 0x0B, R22
ret
SHOW4:
ldi R22, 0b10011000
ldi R23, 0b00000001
add R19, R23
out 0x05, R19
out 0x0B, R22
ret
SHOW5:
ldi R22, 0b10110100
ldi R23, 0b00000001
add R19, R23
out 0x05, R19
out 0x0B, R22
ret
SHOW6:
ldi R22, 0b11110100
ldi R23, 0b00000001
add R19, R23
out 0x05, R19
out 0x0B, R22
ret
SHOW7:
ldi R22, 0b00011100
out 0x0B, R22
ret
SHOW8:
ldi R22, 0b11111100
ldi R23, 0b00000001
add R19, R23
out 0x05, R19
out 0x0B, R22
ret
SHOW9:
ldi R22, 0b10011100
ldi R23, 0b00000001
add R19, R23
out 0x05, R19
out 0x0B, R22
ret
+14 -126
View File
@@ -1,140 +1,28 @@
/*
Showing number 0-9 on a Common Anode 7-segment LED display
Displays the numbers 0-9 on the display, with one second inbetween.
A
---
F | | B
| G |
---
E | | C
| |
---
D
This example code is in the public domain.
*/
// Pin 2-8 is connected to the 7 segments of the display.
int pinA = 2;
int pinB = 3;
int pinC = 4;
int pinD = 5;
int pinE = 6;
int pinF = 7;
int pinG = 8;
int D1 = 9;
int D2 = 10;
int D3 = 11;
int D4 = 12;
extern byte segment;
extern byte digit;
extern "C" {
extern "C" {
void setup_ports();
void select_segment();
void display_segment();
void show_num();
}
void selectseg(){
void display_num(byte seg, byte dig, int del) {
digit = dig;
segment = seg;
select_segment();
}//end of selectSeg()
show_num();
delay(del);
}
void displayseg(){
display_segment();
}//end displayseg();
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pins as outputs.
// pinMode(pinA, OUTPUT);
// pinMode(pinB, OUTPUT);
// pinMode(pinC, OUTPUT);
// pinMode(pinD, OUTPUT);
// pinMode(pinE, OUTPUT);
// pinMode(pinF, OUTPUT);
// pinMode(pinG, OUTPUT);
// pinMode(D1, OUTPUT);
// pinMode(D2, OUTPUT);
// pinMode(D3, OUTPUT);
// pinMode(D4, OUTPUT);
void setup() {
setup_ports();
}
// the loop routine runs over and over again forever:
void loop() {
//Tell which segment im writing to
//0
segment = 0;
selectseg();
digit = 0;
displayseg();
delay(500); // wait for a second
//1
segment = 1;
selectseg();
digit = 1;
displayseg();
delay(500); // wait for a second
//2
segment = 2;
selectseg();
digit = 2;
displayseg();
delay(500); // wait for a second
//3
segment = 3;
selectseg();
digit = 3;
displayseg();
delay(500); // wait for a second
//everything below this
//4
segment = 0;
selectseg();
digit = 4;
displayseg();
delay(500); // wait for a second
//5
segment = 1;
selectseg();
digit = 5;
displayseg();
delay(500); // wait for a second
//6
segment = 2;
selectseg();
digit = 6;
displayseg();
delay(500); // wait for a second
//7
segment = 3;
selectseg();
digit = 7;
displayseg();
delay(500); // wait for a second
//8
segment = 0;
selectseg();
digit = 8;
displayseg();
delay(500); // wait for a second
//9
segment = 1;
selectseg();
digit = 9;
displayseg();
delay(500); // wait for a second
// for loop simplifies call
for (int i = 0; i <= 9; i++) {
display_num(i % 4, i, 500);
// the i%4 sets the correct segment
}
}