Updated data for ES
This commit is contained in:
parent
d9ac0bd296
commit
1c7296cf33
12 changed files with 185 additions and 77 deletions
|
@ -1,3 +0,0 @@
|
||||||
1. Sort using insertion sort
|
|
||||||
2. [Factorial using recursion](https://git.aadit.cc/aadit/MIT-Curricular/src/branch/main/ES/Lab/LAB5/FACTORIAL.asm)
|
|
||||||
3. Search for an element and store the address
|
|
|
@ -3,29 +3,29 @@
|
||||||
int main(){
|
int main(){
|
||||||
unsigned long x, i, j;
|
unsigned long x, i, j;
|
||||||
// from P1.24 -> 31
|
// from P1.24 -> 31
|
||||||
LPC_PINCON->PINSEL0 = 0; // values
|
LPC_PINCON->PINSEL0 = 0; // values
|
||||||
|
|
||||||
|
LPC_GPIO0->FIODIR = 0xFF<<15;
|
||||||
|
|
||||||
LPC_GPIO0->FIODIR = 0xFF<<15;
|
|
||||||
|
|
||||||
x = 1<<15; // new variable
|
x = 1<<15; // new variable
|
||||||
|
|
||||||
while(1){
|
while(1){
|
||||||
x = 1<<15;
|
x = 1<<15;
|
||||||
|
|
||||||
// LOOP to fill 24->31 incrementally
|
// LOOP to fill 24->31 incrementally
|
||||||
for(i=0;i<8;i++){
|
for(i=0;i<8;i++){
|
||||||
LPC_GPIO0->FIOSET=x;
|
LPC_GPIO0->FIOSET=x;
|
||||||
x = x<<1;
|
x = x<<1;
|
||||||
for(j=0; j<800000; j++);
|
for(j=0; j<800000; j++);
|
||||||
}
|
}
|
||||||
// delay
|
// delay
|
||||||
|
|
||||||
// LOOP to empty 24->31 incrementally.
|
// LOOP to empty 24->31 incrementally.
|
||||||
x = 1<<15;
|
x = 1<<15;
|
||||||
for(i=0;i<8;i++){
|
for(i=0;i<8;i++){
|
||||||
LPC_GPIO0->FIOCLR=x;
|
LPC_GPIO0->FIOCLR=x;
|
||||||
x = x<<1;
|
x = x<<1;
|
||||||
for(j=0; j<800000; j++);
|
for(j=0; j<800000; j++);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
30
ES/Lab/Lab7/JOHNSON_Up_Down_Separate_GPIO.c
Normal file
30
ES/Lab/Lab7/JOHNSON_Up_Down_Separate_GPIO.c
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
#include <LPC17xx.h>
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
unsigned long x, y, i, j;
|
||||||
|
|
||||||
|
LPC_PINCON->PINSEL0 = 0;
|
||||||
|
LPC_GPIO0->FIODIR = 0xFF<<15;
|
||||||
|
LPC_GPIO2->FIODIR = 0x0<<12;
|
||||||
|
|
||||||
|
while(1){
|
||||||
|
x = LPC_GPIO2->FIOPIN & (1 << 12);
|
||||||
|
y = x ? (1<<22) : (1<<15);
|
||||||
|
int dir = x ? 1 : 0;
|
||||||
|
|
||||||
|
for(int k=0; k<2; k++){
|
||||||
|
for(i=0; i<8; i++){
|
||||||
|
LPC_GPIO0->FIOSET = y;
|
||||||
|
y = dir ? y>>1 : y<<1;
|
||||||
|
for(j=0; j<800000; j++);
|
||||||
|
}
|
||||||
|
y = x ? (1<<22) : (1<<15);
|
||||||
|
LPC_GPIO0->FIOCLR = y;
|
||||||
|
}
|
||||||
|
for(i=0; i<8; i++){
|
||||||
|
LPC_GPIO0->FIOCLR = y;
|
||||||
|
y = dir ? y>>1 : y<<1;
|
||||||
|
for(j=0; j<800000; j++);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
89
ES/Lab/Lab8/16keyOn7Seg.c
Normal file
89
ES/Lab/Lab8/16keyOn7Seg.c
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
#include <LPC17xx.h>
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
unsigned long i, c, r;
|
||||||
|
unsigned long candidate = 0xFF;
|
||||||
|
unsigned long stable = 0;
|
||||||
|
unsigned long displayed = 0xFF;
|
||||||
|
unsigned long read_key, rows, seg;
|
||||||
|
unsigned char seven_seg[16] = {
|
||||||
|
0x3F, 0x06, 0x5B, 0x4F,
|
||||||
|
0x66, 0x6D, 0x7D, 0x07,
|
||||||
|
0x7F, 0x6F, 0x77, 0x7C,
|
||||||
|
0x39, 0x5E, 0x79, 0x71
|
||||||
|
};
|
||||||
|
|
||||||
|
// Configure pins as GPIO for used ranges
|
||||||
|
LPC_PINCON->PINSEL0 = 0;
|
||||||
|
LPC_PINCON->PINSEL1 = 0;
|
||||||
|
LPC_PINCON->PINSEL3 = 0;
|
||||||
|
|
||||||
|
// Directions
|
||||||
|
LPC_GPIO0->FIODIR |= (0xFFu << 4); // P0.4..P0.11 -> segments out
|
||||||
|
LPC_GPIO0->FIODIR |= (0x0Fu << 15); // P0.15..P0.18 -> columns out
|
||||||
|
LPC_GPIO0->FIODIR &= ~(0x0Fu << 19); // P0.19..P0.22 -> rows in
|
||||||
|
LPC_GPIO1->FIODIR |= (0x0Fu << 23); // P1.23..P1.26 -> digit enables out
|
||||||
|
|
||||||
|
// Initial states
|
||||||
|
LPC_GPIO0->FIOCLR = (0xFFu << 4); // segments off
|
||||||
|
LPC_GPIO1->FIOCLR = (0x0Fu << 23); // all digits off
|
||||||
|
LPC_GPIO0->FIOSET = (0x0Fu << 15); // all columns high (inactive)
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
read_key = 0xFF;
|
||||||
|
|
||||||
|
// Scan 4 columns
|
||||||
|
for (c = 0; c < 4; c++) {
|
||||||
|
// Set all columns high, then pull one low
|
||||||
|
LPC_GPIO0->FIOSET = (0x0Fu << 15);
|
||||||
|
for (i = 0; i < 50; i++); // short settle delay
|
||||||
|
LPC_GPIO0->FIOCLR = (1u << (15 + c));
|
||||||
|
for (i = 0; i < 200; i++); // settle after driving column
|
||||||
|
|
||||||
|
// Read rows P0.19..P0.22 (active-low). Normalize to 0..15.
|
||||||
|
rows = (LPC_GPIO0->FIOPIN >> 19) & 0x0Fu;
|
||||||
|
|
||||||
|
if (rows != 0x0Fu) {
|
||||||
|
for (r = 0; r < 4; r++) {
|
||||||
|
if (((rows >> r) & 1u) == 0u) {
|
||||||
|
read_key = (c << 2) + r; // c*4 + r, 0..15
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LPC_GPIO0->FIOSET = (0x0Fu << 15); // restore columns high
|
||||||
|
break; // found a key this scan
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Debounce: require 3 consecutive identical reads
|
||||||
|
if (read_key == candidate) {
|
||||||
|
if (stable < 3) stable++;
|
||||||
|
} else {
|
||||||
|
candidate = read_key;
|
||||||
|
stable = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stable >= 3) {
|
||||||
|
if (candidate != 0xFF) {
|
||||||
|
displayed = candidate & 0x0F;
|
||||||
|
}
|
||||||
|
stable = 3; // clamp
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update display if we have a digit
|
||||||
|
if (displayed != 0xFF) {
|
||||||
|
seg = seven_seg[displayed];
|
||||||
|
LPC_GPIO0->FIOCLR = (0xFFu << 4);
|
||||||
|
LPC_GPIO0->FIOSET = ((unsigned long)seg << 4);
|
||||||
|
|
||||||
|
// Enable only digit at P1.23
|
||||||
|
LPC_GPIO1->FIOCLR = (0x0Fu << 23);
|
||||||
|
LPC_GPIO1->FIOSET = (1u << 23);
|
||||||
|
} else {
|
||||||
|
LPC_GPIO1->FIOCLR = (0x0Fu << 23);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pace scanning/debounce timing
|
||||||
|
for (i = 0; i < 3000; i++);
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
int main(void){
|
int main(void){
|
||||||
unsigned long i, j, n;
|
unsigned long i, j, n;
|
||||||
unsigned int x;
|
unsigned int x;
|
||||||
unsigned long number = 0;
|
unsigned long number = 0;
|
||||||
unsigned long count = 0;
|
unsigned long count = 0;
|
||||||
unsigned char seven_seg[16] = {
|
unsigned char seven_seg[16] = {
|
||||||
|
@ -20,8 +20,8 @@ int main(void){
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
n = number;
|
n = number;
|
||||||
x = LPC_GPIO0->FIOPIN & (1 << 21);
|
x = LPC_GPIO0->FIOPIN & (1 << 21);
|
||||||
|
|
||||||
for (i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
LPC_GPIO1->FIOCLR = (0x0F << 23);
|
LPC_GPIO1->FIOCLR = (0x0F << 23);
|
||||||
LPC_GPIO1->FIOSET = (i << 23);
|
LPC_GPIO1->FIOSET = (i << 23);
|
||||||
|
@ -43,5 +43,4 @@ int main(void){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,45 +0,0 @@
|
||||||
#include <LPC17xx.h>
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
unsigned long x, y, i, j;
|
|
||||||
|
|
||||||
// LEDs
|
|
||||||
LPC_PINCON->PINSEL0 = 0;
|
|
||||||
LPC_GPIO0->FIODIR = 0xFF<<15;
|
|
||||||
|
|
||||||
LPC_GPIO2->FIODIR = 0x0<<12;
|
|
||||||
|
|
||||||
while(1){
|
|
||||||
x = LPC_GPIO2->FIOPIN & (1 << 12);
|
|
||||||
if(x){
|
|
||||||
y = 1<<22;
|
|
||||||
for(i=0;i<8;i++){
|
|
||||||
LPC_GPIO0->FIOSET=y;
|
|
||||||
y = y>>1;
|
|
||||||
for(j=0; j<800000; j++);
|
|
||||||
}
|
|
||||||
y = 1<<22;
|
|
||||||
for(i=0;i<8;i++){
|
|
||||||
LPC_GPIO0->FIOCLR=y;
|
|
||||||
y>>=1;
|
|
||||||
for(j=0; j<800000; j++);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!x){
|
|
||||||
y = 1<<15;
|
|
||||||
for(i=0;i<8;i++){
|
|
||||||
LPC_GPIO0->FIOSET=y;
|
|
||||||
y = y<<1;
|
|
||||||
for(j=0; j<800000; j++);
|
|
||||||
}
|
|
||||||
y = 1<<15;
|
|
||||||
for(i=0;i<8;i++){
|
|
||||||
LPC_GPIO0->FIOCLR=y;
|
|
||||||
y = y<<1;
|
|
||||||
for(j=0; j<800000; j++);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -4,9 +4,12 @@
|
||||||
#define EN_CTRL 0x10000000
|
#define EN_CTRL 0x10000000
|
||||||
#define DT_CTRL 0x07800000
|
#define DT_CTRL 0x07800000
|
||||||
|
|
||||||
|
#define LCD_COLS 16
|
||||||
|
|
||||||
unsigned int col = 0;
|
unsigned int col = 0;
|
||||||
unsigned long int temp1 = 0, temp2 = 0, i, j;
|
unsigned long int temp1 = 0, temp2 = 0, i, j;
|
||||||
unsigned char flag1 = 0, flag2 = 0;
|
unsigned char flag1 = 0, flag2 = 0;
|
||||||
|
|
||||||
unsigned char msg[] = ("Long messages work well, heh.");
|
unsigned char msg[] = ("Long messages work well, heh.");
|
||||||
|
|
||||||
void lcd_write(void);
|
void lcd_write(void);
|
||||||
|
@ -17,23 +20,18 @@ unsigned long int init_command[] = {
|
||||||
0x30, 0x30, 0x30, 0x20, 0x28, 0x0C, 0x01, 0x80
|
0x30, 0x30, 0x30, 0x20, 0x28, 0x0C, 0x01, 0x80
|
||||||
};
|
};
|
||||||
|
|
||||||
#define LCD_COLS 16
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
LPC_GPIO0->FIODIR = DT_CTRL | RS_CTRL | EN_CTRL;
|
LPC_GPIO0->FIODIR = DT_CTRL | RS_CTRL | EN_CTRL;
|
||||||
|
|
||||||
flag1 = 0;
|
flag1 = 0;
|
||||||
|
|
||||||
|
|
||||||
for (i = 0; i < 8; i++) {
|
for (i = 0; i < 8; i++) {
|
||||||
temp1 = init_command[i];
|
temp1 = init_command[i];
|
||||||
lcd_write();
|
lcd_write();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
flag1 = 1;
|
flag1 = 1;
|
||||||
|
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
||||||
while (msg[i] != '\0') {
|
while (msg[i] != '\0') {
|
||||||
|
@ -41,13 +39,11 @@ int main() {
|
||||||
flag1 = 0;
|
flag1 = 0;
|
||||||
temp1 = 0xC0;
|
temp1 = 0xC0;
|
||||||
lcd_write();
|
lcd_write();
|
||||||
|
|
||||||
flag1 = 1;
|
flag1 = 1;
|
||||||
} else if (col == (LCD_COLS * 2)) {
|
} else if (col == (LCD_COLS * 2)) {
|
||||||
flag1 = 0;
|
flag1 = 0;
|
||||||
temp1 = 0x80;
|
temp1 = 0x80;
|
||||||
lcd_write();
|
lcd_write();
|
||||||
|
|
||||||
flag1 = 1;
|
flag1 = 1;
|
||||||
col = 0;
|
col = 0;
|
||||||
}
|
}
|
||||||
|
@ -57,8 +53,7 @@ int main() {
|
||||||
col++;
|
col++;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (1)
|
while (1);
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcd_write(void) {
|
void lcd_write(void) {
|
||||||
|
@ -95,8 +90,6 @@ void port_write(void) {
|
||||||
|
|
||||||
void delay_lcd(unsigned long r1) {
|
void delay_lcd(unsigned long r1) {
|
||||||
unsigned long r;
|
unsigned long r;
|
||||||
|
for (r = 0; r < r1; r++);
|
||||||
for (r = 0; r < r1; r++)
|
|
||||||
;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,11 @@
|
||||||
|
|
||||||
#define RS_CTRL 0x08000000
|
#define RS_CTRL 0x08000000
|
||||||
#define EN_CTRL 0x10000000
|
#define EN_CTRL 0x10000000
|
||||||
#define DT_CTRL 0x07800000
|
#define DT_CTRL 0x07800000
|
||||||
|
|
||||||
unsigned long int temp1 = 0, temp2 = 0, i, j;
|
unsigned long int temp1 = 0, temp2 = 0, i, j;
|
||||||
unsigned char flag1 = 0, flag2 = 0;
|
unsigned char flag1 = 0, flag2 = 0;
|
||||||
unsigned char msg[] = ("Santhosh Sir Gr8");
|
unsigned char msg[] = ("We have fun.");
|
||||||
|
|
||||||
void lcd_write(void);
|
void lcd_write(void);
|
||||||
void port_write(void);
|
void port_write(void);
|
||||||
|
@ -23,11 +23,11 @@ int main() {
|
||||||
temp1 = init_command[i];
|
temp1 = init_command[i];
|
||||||
lcd_write();
|
lcd_write();
|
||||||
}
|
}
|
||||||
|
|
||||||
flag1=1;
|
flag1=1;
|
||||||
|
|
||||||
i= 0;
|
i= 0;
|
||||||
|
|
||||||
while(msg[i]!='\0'){
|
while(msg[i]!='\0'){
|
||||||
temp1=msg[i];
|
temp1=msg[i];
|
||||||
i++;
|
i++;
|
||||||
|
|
45
ES/Lab/Lab9/dice.c
Normal file
45
ES/Lab/Lab9/dice.c
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
#include <LPC17xx.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#define RS_CTRL 0x08000000
|
||||||
|
#define EN_CTRL 0x10000000
|
||||||
|
#define DT_CTRL 0x07800000
|
||||||
|
|
||||||
|
unsigned long int temp1 = 0, temp2 = 0, i, j;
|
||||||
|
unsigned char flag1 = 0, flag2 = 0;
|
||||||
|
unsigned char msg[] = ("Dice: ");
|
||||||
|
|
||||||
|
void lcd_write(void);
|
||||||
|
void port_write(void);
|
||||||
|
void delay_lcd(unsigned long);
|
||||||
|
|
||||||
|
unsigned long int init_command[] = {0x30,0x30,0x30,0x20,0x28,0x0C,0x01,0x80};
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
LPC_GPIO0->FIODIR = DT_CTRL | RS_CTRL | EN_CTRL;
|
||||||
|
for (i = 0; i < 8; i++) { temp1 = init_command[i]; flag1 = 0; lcd_write(); }
|
||||||
|
LPC_PINCON->PINSEL3 = 0; LPC_GPIO0->FIODIR &= ~(1 << 21);
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
while ((LPC_GPIO0->FIOPIN & (1 << 21)) != 0);
|
||||||
|
flag1 = 0; temp1 = 0x01; lcd_write(); temp1 = 0x80; lcd_write();
|
||||||
|
flag1 = 1; for (i = 0; msg[i] != '\0'; i++) { temp1 = msg[i]; lcd_write(); }
|
||||||
|
j = (rand() % 6) + 1; temp1 = '0' + j; lcd_write();
|
||||||
|
while ((LPC_GPIO0->FIOPIN & (1 << 21)) == 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void lcd_write(void) {
|
||||||
|
flag2 = (flag1 == 1) ? 0 : (((temp1 == 0x30) || (temp1 == 0x20)) ? 1 : 0);
|
||||||
|
temp2 = (temp1 & 0xF0) << 19; port_write();
|
||||||
|
if (!flag2) { temp2 = (temp1 & 0x0F) << 23; port_write(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
void port_write(void) {
|
||||||
|
LPC_GPIO0->FIOPIN = temp2;
|
||||||
|
if (flag1 == 0) LPC_GPIO0->FIOCLR = RS_CTRL; else LPC_GPIO0->FIOSET = RS_CTRL;
|
||||||
|
LPC_GPIO0->FIOSET = EN_CTRL; delay_lcd(100); LPC_GPIO0->FIOCLR = EN_CTRL;
|
||||||
|
delay_lcd(500000);
|
||||||
|
}
|
||||||
|
|
||||||
|
void delay_lcd(unsigned long r1) { unsigned long r; for (r = 0; r < r1; r++); }
|
Binary file not shown.
BIN
IS/Lab/Lab8/SSE/encrypted_index.bin
Normal file
BIN
IS/Lab/Lab8/SSE/encrypted_index.bin
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue