Compare commits

..

No commits in common. "58a5828629b603816a8f594baf8f72c563eb3182" and "b713e978cf587f9b51879644aac9e1e8f0c31d5e" have entirely different histories.

8 changed files with 0 additions and 402 deletions

View File

@ -1,19 +0,0 @@
#include <detpic32.h>
int reverse_byte(int byte) {
byte = (byte & 0xF0) >> 4 | (byte & 0x0F) << 4;
byte = (byte & 0xCC) >> 2 | (byte & 0x33) << 2;
byte = (byte & 0xAA) >> 1 | (byte & 0x55) << 1;
return byte;
}
int main() {
TRISB |= 0x000F;
TRISE &= 0xFF00;
while (1) {
int sw = PORTB & 0x000F;
int reverse = reverse_byte(sw);
LATE = (LATE & 0xFF00) | sw | reverse;
}
}

View File

@ -1,66 +0,0 @@
.equ ADDR_BASE, 0xBF88
.equ TRISB, 0x6040
.equ PORTB, 0x6050
.equ TRISE, 0x6100
.equ LATE, 0x6120
.data
.text
.globl main
main:
lui $t7, ADDR_BASE
lw $t0, TRISB($t7)
ori $t0, $t0, 0x000F
sw $t0, TRISB($t7)
lw $t0, TRISE($t7)
andi $t0, $t0, 0xFF00
sw $t0, TRISE($t7)
loop:
lw $t0, PORTB($t7)
andi $t0, $t0, 0x000F
move $a0, $t0
addi $sp, $sp, -8
sw $ra, 0($sp)
sw $t0, 4($sp)
jal reverse_byte
lw $ra, 0($sp)
lw $t0, 4($sp)
addi $sp, $sp, 8
or $t0, $t0, $v0
lw $t1, LATE($t7)
andi $t1, $t1, 0xFF00
or $t1, $t1, $t0
sw $t1, LATE($t7)
j loop
jr $ra
reverse_byte:
move $v0, $a0
andi $t0, $v0, 0xF0
srl $t0, $t0, 4
andi $t1, $v0, 0x0F
sll $t1, $t1, 4
or $v0, $t0, $t1
andi $t0, $v0, 0xCC
srl $t0, $t0, 2
andi $t1, $v0, 0x33
sll $t1, $t1, 2
or $v0, $t0, $t1
andi $t0, $v0, 0xAA
srl $t0, $t0, 1
andi $t1, $v0, 0x55
sll $t1, $t1, 1
or $v0, $t0, $t1
jr $ra

View File

@ -1,25 +0,0 @@
#include <detpic32.h>
void delay(unsigned int ms) {
resetCoreTimer();
while (readCoreTimer() < ms * 20000);
}
int main() {
TRISE &= 0xFFF0;
LATE &= 0xFFF0;
while (1) {
char key = inkey();
if ('0' <= key && key <= '3') {
LATE = (LATE & 0xFFF0) | 0x0001 << (key - '0');
} else if (key != '\0') {
LATE = (LATE & 0xFFF0) | 0x000F;
delay(1000);
LATE &= 0xFFF0;
}
}
return 0;
}

View File

@ -1,102 +0,0 @@
.equ INKEY, 1
.equ GETCHAR, 2
.equ PUTCHAR, 3
.equ READ_INT, 4
.equ READ_INT10, 5
.equ PRINT_INT, 6
.equ PRINT_INT10, 7
.equ PRINT_STR, 8
.equ READ_STR, 9
.equ EXIT, 10
.equ READ_CORE_TIMER, 11
.equ RESET_CORE_TIMER, 12
.equ ADDR_BASE, 0xBF88
.equ TRISE, 0x6100
.equ LATE, 0x6120
.data
.text
.globl main
main:
lui $t7, ADDR_BASE
lw $t0, TRISE($t7)
andi $t0, $t0, 0xFFF0
sw $t0, TRISE($t7)
lw $t0, LATE($t7)
andi $t0, $t0, 0xFFF0
sw $t0, LATE($t7)
loop:
li $v0, INKEY
syscall
move $t0, $v0
beq $t0, 0, loop
beq $t0, '0', sw_0
beq $t0, '1', sw_1
beq $t0, '2', sw_2
beq $t0, '3', sw_3
lw $t0, LATE($t7)
andi $t0, $t0, 0xFFF0
ori $t0, $t0, 0x000F
sw $t0, LATE($t7)
li $a0, 1000
move $s0, $ra
jal delay
move $ra, $s0
lw $t0, LATE($t7)
andi $t0, $t0, 0xFFF0
sw $t0, LATE($t7)
j end
sw_0:
lw $t0, LATE($t7)
andi $t0, $t0, 0xFFF0
ori $t0, $t0, 0x0001
sw $t0, LATE($t7)
j end
sw_1:
lw $t0, LATE($t7)
andi $t0, $t0, 0xFFF0
ori $t0, $t0, 0x0002
sw $t0, LATE($t7)
j end
sw_2:
lw $t0, LATE($t7)
andi $t0, $t0, 0xFFF0
ori $t0, $t0, 0x0004
sw $t0, LATE($t7)
j end
sw_3:
lw $t0, LATE($t7)
andi $t0, $t0, 0xFFF0
ori $t0, $t0, 0x0008
sw $t0, LATE($t7)
j end
end:
j loop
jr $ra
delay:
mul $t0, $a0, 20000
li $v0, RESET_CORE_TIMER
syscall
delay_loop:
li $v0, READ_CORE_TIMER
syscall
move $t1, $v0
blt $t1, $t0, delay_loop
jr $ra

View File

@ -1,69 +0,0 @@
#include <detpic32.h>
const unsigned int dis7Scodes[] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D,
0xFD, 0x07, 0x7F, 0x6F, 0x77, 0xFC,
0x39, 0x5E, 0xF9, 0xF1};
void delay(unsigned int ms) {
resetCoreTimer();
while (readCoreTimer() < ms * 20000);
}
typedef enum { HIGH, LOW } flag;
void clearDisplays() {
LATD = (LATD & 0xFF9F) | 0x0040;
LATB &= 0x80FF;
LATD = (LATD & 0xFF9F) | 0x0020;
LATB &= 0x80FF;
}
void send2displays(unsigned char value) {
static flag f = LOW;
char high = dis7Scodes[value >> 4];
char low = dis7Scodes[value & 0x0F];
if (f == HIGH) {
LATD = (LATD & 0xFF9F) | 0x0040;
LATB = (LATB & 0x80FF) | high << 8;
f = LOW;
} else {
LATD = (LATD & 0xFF9F) | 0x0020;
LATB = (LATB & 0x80FF) | low << 8;
f = HIGH;
}
}
int main() {
TRISE &= 0xFFF0;
TRISD &= 0xFF9F;
TRISB &= 0x80FF;
LATE &= 0xFFF0;
clearDisplays();
char lastKey;
while (1) {
char key = inkey();
if ('0' <= key && key <= '3') {
LATE = (LATE & 0xFFF0) | 0x0001 << (key - '0');
lastKey = key;
} else if (key != '\0') {
LATE = (LATE & 0xFFF0) | 0x000F;
resetCoreTimer();
while (readCoreTimer() < 20000000)
send2displays(0xFF);
LATE &= 0xFFF0;
clearDisplays();
lastKey = 0xFF;
}
if ('0' <= lastKey && lastKey <= '3') {
send2displays(lastKey - '0');
delay(10);
}
}
return 0;
}

View File

@ -1,76 +0,0 @@
#include <detpic32.h>
const unsigned int dis7Scodes[] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D,
0xFD, 0x07, 0x7F, 0x6F, 0x77, 0xFC,
0x39, 0x5E, 0xF9, 0xF1};
void delay(unsigned int ms) {
resetCoreTimer();
while (readCoreTimer() < ms * 20000);
}
typedef enum { HIGH, LOW } flag;
void send2displays(unsigned char value) {
static flag f = LOW;
if (f == HIGH) {
LATD = (LATD & 0xFF9F) | 0x0040;
LATB = (LATB & 0x80FF) | dis7Scodes[value >> 4] << 8;
f = LOW;
} else {
LATD = (LATD & 0xFF9F) | 0x0020;
LATB = (LATB & 0x80FF) | dis7Scodes[value & 0x0F] << 8;
f = HIGH;
}
}
void clearDisplays() {
LATD = (LATD & 0xFF9F) | 0x0040;
LATB &= 0x80FF;
LATD = (LATD & 0xFF9F) | 0x0020;
LATB &= 0x80FF;
}
unsigned char toBdc(unsigned char value) {
return ((value / 10) << 4) + (value % 10);
}
int main() {
TRISB &= 0x80FF;
TRISD &= 0xFF9F;
int counter = 0;
char factor = 0;
int display_freq = 0;
int i = 0;
while (1) {
putChar('\r');
printInt(counter, 10 | 2 << 16);
char key = inkey();
if ('0' <= key && key <= '4') {
factor = key - '0';
}
if (key == '\n') {
display_freq = !display_freq;
}
if (display_freq) {
printStr(" -> ");
printInt(2 * (1 + factor), 10 | 2 << 16);
printStr(" Hz");
send2displays(toBdc(2 * (1 + factor)));
} else {
printStr(" \r");
clearDisplays();
}
if (i++ >= 50 / (2 * (1 + factor))) {
counter = (counter + 1) % 100;
i = 0;
}
delay(20);
}
return 0;
}

View File

@ -1,45 +0,0 @@
#include <detpic32.h>
void delay(unsigned int ms) {
resetCoreTimer();
while (readCoreTimer() < ms * 20000);
}
int main() {
TRISBbits.TRISB4 = 1;
AD1PCFGbits.PCFG4 = 0;
AD1CON1bits.SSRC = 7;
AD1CON1bits.CLRASAM = 1;
AD1CON3bits.SAMC = 16;
AD1CON2bits.SMPI = 15;
AD1CHSbits.CH0SA = 4;
AD1CON1bits.ON = 1;
TRISB |= 0x000F;
int c = 0;
int factor = 1;
while (1) {
if (c++ >= 100 / factor) {
c = 0;
putChar('\r');
printStr("DS=");
char input = PORTB & 0x000F;
int i = 0;
for (; i < 4; i++) {
putChar((input >> (3 - i) & 0x0001) + '0');
}
}
AD1CON1bits.ASAM = 1;
while (IFS1bits.AD1IF == 0);
int value = ADC1BUF0;
int total = 0;
int *p = (int *)(&ADC1BUF0);
for (; p <= (int *)(&ADC1BUFF); p+=4)
total += *p;
factor = (total / 16) / 205 + 1;
delay(10);
}
return 0;
}