Skip to content
This repository was archived by the owner on Nov 29, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions paraoleg/lab1-BasicIO/main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/******************************************************************************/
/* Files to Include */
/******************************************************************************/
#ifdef __XC32
#include <xc.h> /* Defines special function registers, CP0 regs */
#endif
Expand All @@ -11,21 +8,9 @@
#include "system.h" /* System funct/params, like osc/periph config */
#include "user.h" /* User funct/params, such as InitApp */

/******************************************************************************/
/* Global Variable Declaration */
/******************************************************************************/

/* i.e. uint32_t <variable_name>; */

/******************************************************************************/
/* Main Program */
/******************************************************************************/

int32_t main(void)
{
/* Initialize I/O
* and Peripherals
* for application */
InitApp();

InitApp(); // Initialize I/O and Peripherals for application
Scan_LEDs();
}
16 changes: 0 additions & 16 deletions paraoleg/lab1-BasicIO/system.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/******************************************************************************/
/* Files to Include */
/******************************************************************************/

#ifdef __XC32
#include <xc.h> /* Defines special funciton registers, CP0 regs */
#endif
Expand All @@ -10,15 +6,3 @@
#include <stdint.h> /* For uint32_t definition */
#include <stdbool.h> /* For true/false definition */
#include "system.h" /* variables/params used by system.c */

/******************************************************************************/
/* System Level Functions */
/* */
/* Custom oscillator configuration funtions, reset source evaluation */
/* functions, and other non-peripheral microcontroller initialization */
/* functions get placed in system.c */
/* */
/******************************************************************************/

/* <Initialize variables in system.h and put code for system code here.> */

107 changes: 46 additions & 61 deletions paraoleg/lab1-BasicIO/user.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/******************************************************************************/
/* Files to Include */
/******************************************************************************/

#ifdef __XC32
#include <xc.h> /* Defines special function registers, CP0 regs */
#endif
Expand All @@ -10,35 +6,25 @@
#include <stdbool.h> /* For true/false definition */
#include "user.h" /* variables/params used by user.c */

/******************************************************************************/
/* User Functions */

/******************************************************************************/

/* Setup analog functionality and port direction */
void InitApp(void) {
/* Setup analog functionality and port direction */


// LED output
// Disable analog mode for G15
ANSELGbits.ANSG15 = 0;
// Set direction to output for G15
TRISGbits.TRISG15 = 0;
// Disable analog mode for pins
ANSELG &= ~((1 << 6) | (1 << 15));
ANSELB &= ~(1 << 11);

// Disable analog mode for B11
ANSELBbits.ANSB11 = 0;
// Set direction to output for B11
TRISBbits.TRISB11 = 0;
// Set direction to output for pins
TTRISG &= ~((1 << 6) | (1 << 15));
TRISB &= ~(1 << 11);

// Disable analog mode for D4
PORTDbits.RD4 = 0; // For LED2 on PORTD pin 4 is no analog option so ANSELDbits.ANSD4 = 0 will not compile
// Set direction to output for D4
TRISDbits.TRISD4 = 0;

// Disable analog mode for G6
ANSELGbits.ANSG6 = 0;
// Set direction to output for G6
TRISGbits.TRISG6 = 0;

TRISD &= ~(1 << 4);

// Initialize outputs for other LEDs

// Turn on LEDs for testing
Expand All @@ -61,17 +47,14 @@ void InitApp(void) {

// BTN1 input
// Disable analog mode
ANSELAbits.ANSA5 = 0;
ANSELA &= ~(1 << 5);
// Set directions to input
TRISAbits.TRISA5 = 1;

// Initialize input for BTN2
TRISAbits.TRISA5 = 1;
TRISA |= (1 << 5)|(1 << 4);

// Test switches
while (1) {
LD1_PORT_BIT = BTN1_PORT_BIT;
LD2_PORT_BIT = BTN2_PORT_BIT;
LD1_PORT_BIT = BTN1_PORT_BIT;
LD2_PORT_BIT = BTN2_PORT_BIT;
};
}

Expand Down Expand Up @@ -99,36 +82,38 @@ void Flash_LED(void) {
}

void Scan_LEDs(void) {
int LED_state = 1; // 1 on (initial value), 0 off
int delay_count=1000000;

while (1) {
if (BTN1_PORT_BIT == 1) { // ?????? 1 ??????
delay_count = 300000;
} else { // ?????? 1 ?? ??????
delay_count = 1000000;
}

if (BTN2_PORT_BIT == 1) { // ?????? 2 ??????
// ????????? ??? ??????????
LD1_PORT_BIT = 0;
LD2_PORT_BIT = 0;
LD3_PORT_BIT = 0;
LD4_PORT_BIT = 0;
} else {
LD1_PORT_BIT = LED_state;
Delay(delay_count);
LD2_PORT_BIT = LED_state;
Delay(delay_count);
LD3_PORT_BIT = LED_state;
Delay(delay_count);
LD4_PORT_BIT = LED_state;
Delay(delay_count);

// next time, set LEDs to opposite state

LED_state = 1 - LED_state;
}
}
int LED_state = 1; // 1 on (initial value), 0 off
int delay_count=1000000;

while (1) {
if (BTN1_PORT_BIT == 1) { //first button is pressed
delay_count = 300000;
}
else {
delay_count = 1000000;
}

if (BTN2_PORT_BIT == 1) { //second button is pressed
LD1_PORT_BIT = 0;
LD2_PORT_BIT = 0;
LD3_PORT_BIT = 0;
LD4_PORT_BIT = 0;
}
else {
LD1_PORT_BIT = LED_state;
Delay(delay_count);
LD2_PORT_BIT = LED_state;
Delay(delay_count);
LD3_PORT_BIT = LED_state;
Delay(delay_count);
LD4_PORT_BIT = LED_state;
Delay(delay_count);

// next time, set LEDs to opposite state

LED_state = 1 - LED_state;
}
}
}