https://github.com/risoflora/brook4xc8
Brook4-XC8 is a small XC8 library for all 8-bit PIC MCUs development.
https://github.com/risoflora/brook4xc8
8-bit adc automation embedded iot mcu mechatronics microchip microcontroller pic robotics
Last synced: about 2 months ago
JSON representation
Brook4-XC8 is a small XC8 library for all 8-bit PIC MCUs development.
- Host: GitHub
- URL: https://github.com/risoflora/brook4xc8
- Owner: risoflora
- License: lgpl-3.0
- Created: 2017-09-01T22:06:38.000Z (almost 8 years ago)
- Default Branch: main
- Last Pushed: 2022-01-14T03:49:05.000Z (over 3 years ago)
- Last Synced: 2025-04-07T09:03:19.313Z (3 months ago)
- Topics: 8-bit, adc, automation, embedded, iot, mcu, mechatronics, microchip, microcontroller, pic, robotics
- Language: C
- Homepage:
- Size: 449 KB
- Stars: 5
- Watchers: 6
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Brook4-XC8
Brook4-XC8 is a small XC8 library for all 8-bit PIC MCUs development.
# Supported compiler
[MPLAB XC8 C-Compiler v1.45](https://www.microchip.com/forums/m1029676.aspx), which can be downloaded [here](https://www.microchip.com/development-tools/pic-and-dspic-downloads-archive).
# LCD driver
## Circuit

## Code
```c
#include
#includeB4X_LCD_SET_RS(PORTB, 0); /* Set LCD RS port. */
B4X_LCD_SET_E(PORTB, 1); /* Set LCD E port. */
B4X_LCD_SET_D4(PORTB, 2); /* Set LCD D4 port. */
B4X_LCD_SET_D5(PORTB, 3); /* Set LCD D5 port. */
B4X_LCD_SET_D6(PORTB, 4); /* Set LCD D6 port. */
B4X_LCD_SET_D7(PORTB, 5); /* Set LCD D7 port. */void main() {
CMCON = 0x07; /* Disable comparator. */
TRISB = 0xc0; /* RB<5:0> as output. */
b4x_lcd_init(); /* Initialize LCD. */
b4x_lcd_write(0, 0, "HELLO WORLD!"); /* Writes "HELLO WORLD!" on the LCD. */
B4X_RUN(); /* Main loop. */
}
```# Switch handling
## Circuit

## Code
```c
#include
#include#define SW1 RB0 /* Set SW1 pin. */
#define LED_GREEN RB1 /* Set green LED pin. */
#define SW2 RB2 /* Set SW2 pin. */
#define LED_RED RB3 /* Set red LED pin. */
#define SW3 RB4 /* Set WS3 pin. */
#define LED_BLUE RB5 /* Set blue LED pin. */void main() {
CMCON = 0x07; /* Disable comparator. */
TRISB = 0xd5; /* Switches: RB<2:0>; LEDs: RB<3:1>. */
LED_GREEN = 0; /* Turn off green LED. */
LED_RED = 0; /* Turn off red LED. */
LED_BLUE = 0; /* Turn off blue LED. */B4X_RUN() { /* Main loop. */
B4X_SW_CLICK(SW1) { /* On/off green LED. */
B4X_SW_DEBOUNCE(SW1);
LED_GREEN = !LED_GREEN;
}B4X_SW_nCLICK(SW2) { /* On/off red LED. */
B4X_SW_DEBOUNCE(SW2);
B4X_SW_TOGGLE(LED_RED);
}B4X_SW_LONG_CLICK(SW3) { /* On/off blue LED (using long click). */
B4X_SW_DEBOUNCE(SW3);
B4X_SW_TOGGLE(LED_BLUE);
}
}
}
```
# ADC reading## Circuit

## Code
```c
#include
#include
#includeB4X_LCD_SET_RS(PORTC, 0); /* Set LCD RS port. */
B4X_LCD_SET_E(PORTC, 1); /* Set LCD E port. */
B4X_LCD_SET_D4(PORTC, 2); /* Set LCD D4 port. */
B4X_LCD_SET_D5(PORTC, 3); /* Set LCD D5 port. */
B4X_LCD_SET_D6(PORTC, 4); /* Set LCD D6 port. */
B4X_LCD_SET_D7(PORTC, 5); /* Set LCD D7 port. */int ADC_VAL, ADC_OLD_VAL; /* Variables to get ADC value and to avoid display blinking. */
char ADC_VAL_STR[4]; /* Variable to display ADC value as string. */void main() {
CMCON = 0x07; /* Disable comparator. */
TRISA = 0xff; /* RA<7:0> as input. */
TRISC = 0xc0; /* RC<5:0> as output. */
ANSEL = 0x02; /* Enable AN 1. */
b4x_adc_init(); /* Initialize ADC. */
b4x_lcd_init(); /* Initialize LCD. */B4X_RUN() { /* Main loop. */
/* Update display if new ADC value is different from the already read. */
if ((ADC_VAL = b4x_adc_read(1)) != ADC_OLD_VAL) { /* Read ADC value from channel 1. */
ADC_OLD_VAL = ADC_VAL; /* Hold new ADC value. */
itoa(ADC_VAL_STR, ADC_VAL, 10); /* Convert ADC value to string. */
b4x_lcd_write(0, 0, "VALUE: "); /* Print initial label. */
b4x_lcd_erase(7, 0, sizeof (ADC_VAL_STR)); /* Erase previous printed ADC value. */
b4x_lcd_write_str(7, 0, ADC_VAL_STR); /* Print new ADC value. */
}
}
}
```# EEPROM writing/reading
## Circuit

## Code
```c
#include
#include
#include#define LED GP0 /* Set GP0 as LED driver. */
volatile bit LED_STATUS; /* Handle LED status. */
void main() {
CMCON = 0x07; /* Disable comparator. */
TRISIO = 0x3e; /* Configure output pin. */B4X_RUN() { /* Main loop. */
B4X_SW_TOGGLE(LED_STATUS); /* Toggle LED status. */
B4X_EEPROM_WRITE(3, (unsigned char) LED_STATUS); /* Write LED status to EEPROM. */
B4X_EEPROM_READ(3, LED); /* Read LED status from EEPROM. */
__delay_ms(500); /* Wait for 500 ms. */
}
}
```# Licensing
Brook4-XC8 is released under GNU Lesser General Public License v3.0. Check the [LICENSE file](https://github.com/risoflora/brook4xc8/blob/main/LICENSE) for more details.
[](https://www.gnu.org/licenses/lgpl-3.0.html)