Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Added 2 examples for FPGA and Microcontroller work
- Loading branch information
0 parents
commit 1258f22
Showing
7 changed files
with
178 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Deployed on at ATMega 328p | ||
|
||
A light sensor is setup up to function as a button. | ||
-ADC reads light sensor. When threshold voltage is reached, and held for 1 second, a counter is incremented. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#define F_CPU 16000000UL | ||
#include <avr/io.h> | ||
#include <avr/pgmspace.h> | ||
#include <inttypes.h> | ||
#include <avr/interrupt.h> | ||
#include <util/delay.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include "lcd_lib.h" | ||
// PWM variables | ||
volatile unsigned int Ain; | ||
volatile float Voltage; | ||
// LCD Strings | ||
char lcd_buffer[17]; // LCD display buffer | ||
const uint8_t LCD_Volage[] PROGMEM = "Voltage: "; | ||
const uint8_t ButtonTaps[] PROGMEM = "Taps: "; | ||
int oneshot = 0; | ||
int waitForLower = 0; | ||
int count = 0; | ||
int state = 0; | ||
|
||
// All initializations | ||
void initialize_all(void) | ||
{ | ||
// start the LCD | ||
initialize_LCD(); | ||
LCDcursorOFF(); | ||
LCDclr(); | ||
CopyStringtoLCD(ButtonTaps, 0, 0); | ||
//CopyStringtoLCD(ButtonTaps, 0, 1); | ||
// ADC Setup | ||
ADMUX |= (1<<MUX2) | (1<<MUX1); // Select ADC Channel 6 | ||
ADCSRA |= (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0); // Set ADC prescaler to 128 | ||
ADCSRA |= (1<<ADEN); // Enable ADC circuit | ||
} | ||
|
||
void start_ADC_and_wait() | ||
{ | ||
// Start A to D conversion | ||
ADCSRA |= (1<<ADSC); | ||
// Wait until this conversion is completed | ||
while((ADCSRA & (1<<ADSC))); | ||
} | ||
|
||
int main(void) | ||
{ | ||
initialize_all(); | ||
while(1) | ||
{ | ||
// Convert A to D | ||
start_ADC_and_wait(); | ||
// Read the ADC value | ||
Ain = (ADCL); // First read lower byte | ||
Ain |= (ADCH<<8); // Then read upper byte | ||
// Typecast the volatile integer into floating type data, | ||
// divide by maximum 10-bit value, and | ||
// multiply by 5V for normalization | ||
Voltage = (float)Ain/1024.00 * 5.00; | ||
if((Voltage >= 1) && waitForLower == 0) | ||
{ | ||
oneshot = 1; | ||
waitForLower = 1; | ||
state = 1; //Pressed | ||
} | ||
if(Voltage < 0.5) | ||
{ | ||
waitForLower = 0; | ||
state = 0; //Released | ||
} | ||
if(oneshot == 1) | ||
{ | ||
oneshot = 0; | ||
count++; | ||
} | ||
// Write Voltage to string format and print | ||
// (3 char string + “.” + 3 decimal places) | ||
dtostrf(count, 4, 3, lcd_buffer); | ||
LCDGotoXY(6,0); | ||
LCDstring((uint8_t*)lcd_buffer, strlen(lcd_buffer)); | ||
dtostrf(state, 4, 3, lcd_buffer); | ||
LCDGotoXY(6,1); | ||
LCDstring((uint8_t*)lcd_buffer, strlen(lcd_buffer)); | ||
_delay_ms(100); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Deployed over ATMega328p | ||
|
||
Setup non-blocking internal SPI. The program analizes the time it takes to communicate between the master and slave. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Deployed on Nexys4 DDR | ||
|
||
Program receives Keyboard data, and displays that data to a screen via VGA. The program effectively functions as a basic word processor. |
Binary file not shown.