LTlib LaurTec Library
4.0.0 Beta
Open Source C Library for Microchip Microcontrollers based on XC8 Compiler
Main Page
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
main.c
Go to the documentation of this file.
1
#include <xc.h>
2
3
#include "
LTlib.h
"
4
5
#include "
module_IO.h
"
6
#include "
module_IO.c
"
7
8
//******************************************************************************
9
//The software reads PORTB where you have 4 buttons on RB4-RB7 (BT1-BT4).
10
//The button that gets pressed is shown on PORTD where you need to connects
11
// 4 LEDs from RD0 to RD3.
12
//******************************************************************************
13
14
int
main
(
void
) {
15
16
unsigned
char
data;
17
18
IO_set_port_direction
(
IO_PORTB
,
IO_BIT4_IN
+
IO_BIT5_IN
+
IO_BIT6_IN
+
IO_BIT7_IN
);
19
IO_set_port_direction
(
IO_PORTD
,
IO_ALL_PORT_OUTPUT
);
20
21
IO_enable_pull_up_resistors
(
IO_PORTB
,
IO_BIT4
+
IO_BIT5
+
IO_BIT6
+
IO_BIT7
);
22
23
while
(1){
24
//It shifts 4 positions to get BT1 associated with LED1 on PORD bit 0
25
data =
IO_read_port
(
IO_PORTB
);
26
IO_write_port
(
IO_PORTD
,(~data >> 4) & 0x0F);
27
}
28
}
LTlib_v_4.0.0
ex
PIC18
_module_IO
01 - module_IO_Read_Buttons_and_LED.X
main.c
Generated on Sun Feb 21 2016 13:52:58 for LTlib LaurTec Library by
1.8.3.1