-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Abhijith Sriram
committed
Oct 1, 2024
1 parent
67e0c1f
commit 74ddf21
Showing
12 changed files
with
154 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,2 @@ | ||
vsCode_workspace.code-workspace | ||
out/ |
Binary file not shown.
Binary file not shown.
Binary file added
BIN
10.4 MB
...O’Reilly Media -- 9781098151546 -- a1be7e718d80a4cee110f5b36104ce4a -- Anna’s Archive.pdf
Binary file not shown.
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,16 @@ | ||
#include "utils.h" | ||
#include "pin.h" | ||
|
||
void main() | ||
{ | ||
/* Configure pin PB5 to output*/ | ||
Configure_pinPort(PORTB, (uint8_t)PINB5, OUTPUT); | ||
|
||
/* The main loop for the application */ | ||
while(1) | ||
{ | ||
Write_pin(PORTB, (uint8_t)PINB5, PIN_HIGH); | ||
Delay(); | ||
Write_pin(PORTB, (uint8_t)PINB5, PIN_LOW); | ||
} | ||
} |
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 @@ | ||
#include <stdint.h> | ||
|
||
typedef uint8_t bool_t; |
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,9 @@ | ||
/* | ||
* File containing the address for registers and other related stuff | ||
* | ||
*/ | ||
#include <stdint.h> | ||
|
||
#define GPIOB (0x23U) | ||
#define GPIOC (0x26U) | ||
#define GPIOD (0x29U) |
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,42 @@ | ||
#include <stdint.h> | ||
#include "memory_cal.h" | ||
#include "pin.h" | ||
|
||
/* | ||
* Function to configure ports for read or write | ||
* | ||
* INPUT | ||
* @param gpio *port - pointer to a general purpose IO register | ||
use macros PORTB/PORTC/PORTD | ||
* @param uint8_t pin - the pin number from the enum PINB/PINC/PIND | ||
typecast to uint8_t | ||
* @param PIN_CONFIG pin_config - Pin configuration INPUT/OUTPUT | ||
* | ||
* OUTPUT | ||
* None | ||
*/ | ||
void Configure_pinPort(gpio *port, uint8_t pin, PIN_CONFIG pin_config) | ||
{ | ||
port->ddr |= (((uint8_t) pin_config) << pin); | ||
if(pin_config == INPUT) | ||
{ | ||
/* This is to activate the pull-up resistor */ | ||
port->port |= (((uint8_t) 1) << pin); | ||
} | ||
else | ||
{ | ||
/* do nothing */ | ||
} | ||
} | ||
|
||
PIN_VALUE Read_pin(gpio* port, uint8_t pin) | ||
{ | ||
uint8_t mask = ((uint8_t) 1 << pin); | ||
uint8_t pin_value = (port->pin & mask) >> pin; | ||
return (PIN_VALUE) pin_value; | ||
} | ||
|
||
void Write_pin(gpio* port, uint8_t pin, PIN_VALUE value) | ||
{ | ||
port->pin |= (((uint8_t) value) << pin); | ||
} |
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,68 @@ | ||
#include <stdint.h> | ||
#include "memory_cal.h" | ||
|
||
/* Data types */ | ||
typedef struct | ||
{ | ||
volatile uint8_t pin; | ||
volatile uint8_t ddr; | ||
volatile uint8_t port; | ||
}gpio; | ||
|
||
typedef enum | ||
{ | ||
PINB0 = 0, | ||
PINB1, | ||
PINB2, | ||
PINB3, | ||
PINB4, | ||
PINB5, | ||
PINB6, | ||
PINB7 | ||
} PINB; | ||
|
||
typedef enum | ||
{ | ||
PINC0 = 0, | ||
PINC1, | ||
PINC2, | ||
PINC3, | ||
PINC4, | ||
PINC5, | ||
PINC6 | ||
} PINC; | ||
|
||
typedef enum | ||
{ | ||
PIND0 = 0, | ||
PIND1, | ||
PIND2, | ||
PIND3, | ||
PIND4, | ||
PIND5, | ||
PIND6, | ||
PIND7 | ||
} PIND; | ||
|
||
typedef enum | ||
{ | ||
INPUT = 0, | ||
OUTPUT | ||
}PIN_CONFIG; | ||
|
||
typedef enum | ||
{ | ||
PIN_LOW = 0, | ||
PIN_HIGH | ||
}PIN_VALUE; | ||
|
||
/* Macros */ | ||
#define PORTB (volatile gpio*) GPIOB | ||
#define PORTC (volatile gpio*) GPIOC | ||
#define PORTD (volatile gpio*) GPIOD | ||
|
||
/* Function prototypes */ | ||
|
||
void Configure_pinPort(gpio *port, uint8_t pin, PIN_CONFIG pin_config); | ||
PIN_VALUE Read_pin(gpio* port, uint8_t pin); | ||
void Write_pin(gpio* port, uint8_t pin, PIN_VALUE value); |
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,10 @@ | ||
#include "utils.h" | ||
|
||
void Delay(void) | ||
{ | ||
volatile uint8_t temp; | ||
for (uint32_t indx=(uint32_t)0; indx<DELAY_INDEX; indx ) | ||
{ | ||
temp=((uint8_t)0); | ||
} | ||
} |
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 @@ | ||
#include <stdint.h> | ||
|
||
#define DELAY_INDEX (uint32_t) 1000000 | ||
void Delay(void); |