{"id":19904582,"url":"https://github.com/risoflora/brook4xc8","last_synced_at":"2025-05-03T00:31:40.648Z","repository":{"id":139842441,"uuid":"102156468","full_name":"risoflora/brook4xc8","owner":"risoflora","description":"Brook4-XC8 is a small XC8 library for all 8-bit PIC MCUs development.","archived":false,"fork":false,"pushed_at":"2022-01-14T03:49:05.000Z","size":460,"stargazers_count":5,"open_issues_count":0,"forks_count":4,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-04-07T09:03:19.313Z","etag":null,"topics":["8-bit","adc","automation","embedded","iot","mcu","mechatronics","microchip","microcontroller","pic","robotics"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/risoflora.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-09-01T22:06:38.000Z","updated_at":"2024-09-06T18:00:43.000Z","dependencies_parsed_at":null,"dependency_job_id":"179860c7-5699-4544-bb9f-85332d473e14","html_url":"https://github.com/risoflora/brook4xc8","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/risoflora%2Fbrook4xc8","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/risoflora%2Fbrook4xc8/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/risoflora%2Fbrook4xc8/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/risoflora%2Fbrook4xc8/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/risoflora","download_url":"https://codeload.github.com/risoflora/brook4xc8/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252126581,"owners_count":21698964,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["8-bit","adc","automation","embedded","iot","mcu","mechatronics","microchip","microcontroller","pic","robotics"],"created_at":"2024-11-12T20:28:57.394Z","updated_at":"2025-05-03T00:31:40.642Z","avatar_url":"https://github.com/risoflora.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Brook4-XC8\n\nBrook4-XC8 is a small XC8 library for all 8-bit PIC MCUs development.\n\n# Supported compiler\n\n[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).\n\n# LCD driver\n\n## Circuit\n\n![LCD driver schematic](https://raw.githubusercontent.com/brook-dev/brook4xc8/main/examples/brook4xc8-lcd.X/schematic.png)\n\n## Code\n\n```c\n#include \u003cb4x_macros.h\u003e\n#include \u003cb4x_lcd.h\u003e\n\nB4X_LCD_SET_RS(PORTB, 0); /* Set LCD RS port. */\nB4X_LCD_SET_E(PORTB, 1); /* Set LCD E port. */\nB4X_LCD_SET_D4(PORTB, 2); /* Set LCD D4 port. */\nB4X_LCD_SET_D5(PORTB, 3); /* Set LCD D5 port. */\nB4X_LCD_SET_D6(PORTB, 4); /* Set LCD D6 port. */\nB4X_LCD_SET_D7(PORTB, 5); /* Set LCD D7 port. */\n\nvoid main() {\n    CMCON = 0x07; /* Disable comparator. */\n    TRISB = 0xc0; /* RB\u003c5:0\u003e as output. */\n    b4x_lcd_init(); /* Initialize LCD. */\n    b4x_lcd_write(0, 0, \"HELLO WORLD!\"); /* Writes \"HELLO WORLD!\" on the LCD. */\n    B4X_RUN(); /* Main loop. */\n}\n```\n\n# Switch handling\n\n## Circuit\n\n![Switch schematic](https://raw.githubusercontent.com/brook-dev/brook4xc8/main/examples/brook4xc8-switch.X/schematic.png)\n\n## Code\n\n```c\n#include \u003cb4x_macros.h\u003e\n#include \u003cb4x_switch.h\u003e\n\n#define SW1 RB0 /* Set SW1 pin. */\n#define LED_GREEN RB1 /* Set green LED pin. */\n#define SW2 RB2 /* Set SW2 pin. */\n#define LED_RED RB3 /* Set red LED pin. */\n#define SW3 RB4 /* Set WS3 pin. */\n#define LED_BLUE RB5 /* Set blue LED pin. */\n\nvoid main() {\n    CMCON = 0x07; /* Disable comparator. */\n    TRISB = 0xd5; /* Switches: RB\u003c2:0\u003e; LEDs: RB\u003c3:1\u003e. */\n    LED_GREEN = 0; /* Turn off green LED. */\n    LED_RED = 0; /* Turn off red LED. */\n    LED_BLUE = 0; /* Turn off blue LED. */\n\n    B4X_RUN() { /* Main loop. */\n\n        B4X_SW_CLICK(SW1) { /* On/off green LED. */\n            B4X_SW_DEBOUNCE(SW1);\n            LED_GREEN = !LED_GREEN;\n        }\n\n        B4X_SW_nCLICK(SW2) { /* On/off red LED. */\n            B4X_SW_DEBOUNCE(SW2);\n            B4X_SW_TOGGLE(LED_RED);\n        }\n\n        B4X_SW_LONG_CLICK(SW3) { /* On/off blue LED (using long click). */\n            B4X_SW_DEBOUNCE(SW3);\n            B4X_SW_TOGGLE(LED_BLUE);\n        }\n    }\n}\n```\n# ADC reading\n\n## Circuit\n\n![ADC schematic](https://raw.githubusercontent.com/brook-dev/brook4xc8/main/examples/brook4xc8-adc.X/schematic.png)\n\n## Code\n\n```c\n#include \u003cstdlib.h\u003e\n#include \u003cb4x_lcd.h\u003e\n#include \u003cb4x_adc.h\u003e\n\nB4X_LCD_SET_RS(PORTC, 0); /* Set LCD RS port. */\nB4X_LCD_SET_E(PORTC, 1); /* Set LCD E port. */\nB4X_LCD_SET_D4(PORTC, 2); /* Set LCD D4 port. */\nB4X_LCD_SET_D5(PORTC, 3); /* Set LCD D5 port. */\nB4X_LCD_SET_D6(PORTC, 4); /* Set LCD D6 port. */\nB4X_LCD_SET_D7(PORTC, 5); /* Set LCD D7 port. */\n\nint ADC_VAL, ADC_OLD_VAL; /* Variables to get ADC value and to avoid display blinking. */\nchar ADC_VAL_STR[4]; /* Variable to display ADC value as string. */\n\nvoid main() {\n    CMCON = 0x07; /* Disable comparator. */\n    TRISA = 0xff; /* RA\u003c7:0\u003e as input. */\n    TRISC = 0xc0; /* RC\u003c5:0\u003e as output. */\n    ANSEL = 0x02; /* Enable AN 1. */\n    b4x_adc_init(); /* Initialize ADC. */\n    b4x_lcd_init(); /* Initialize LCD. */\n\n    B4X_RUN() { /* Main loop. */\n        /* Update display if new ADC value is different from the already read. */\n        if ((ADC_VAL = b4x_adc_read(1)) != ADC_OLD_VAL) { /* Read ADC value from channel 1. */\n            ADC_OLD_VAL = ADC_VAL; /* Hold new ADC value. */\n            itoa(ADC_VAL_STR, ADC_VAL, 10); /* Convert ADC value to string. */\n            b4x_lcd_write(0, 0, \"VALUE: \"); /* Print initial label. */\n            b4x_lcd_erase(7, 0, sizeof (ADC_VAL_STR)); /* Erase previous printed ADC value. */\n            b4x_lcd_write_str(7, 0, ADC_VAL_STR); /* Print new ADC value. */\n        }\n    }\n}\n```\n\n# EEPROM writing/reading\n\n## Circuit\n\n![EEPROM schematic](https://raw.githubusercontent.com/brook-dev/brook4xc8/main/examples/brook4xc8-eeprom.X/schematic.gif)\n\n## Code\n\n```c\n#include \u003cb4x_macros.h\u003e\n#include \u003cb4x_switch.h\u003e\n#include \u003cb4x_eeprom.h\u003e\n\n#define LED GP0 /* Set GP0 as LED driver. */\n\nvolatile bit LED_STATUS; /* Handle LED status. */\n\nvoid main() {\n    CMCON = 0x07; /* Disable comparator. */\n    TRISIO = 0x3e; /* Configure output pin. */\n\n    B4X_RUN() { /* Main loop. */\n        B4X_SW_TOGGLE(LED_STATUS); /* Toggle LED status. */\n        B4X_EEPROM_WRITE(3, (unsigned char) LED_STATUS); /* Write LED status to EEPROM. */\n        B4X_EEPROM_READ(3, LED); /* Read LED status from EEPROM. */\n        __delay_ms(500); /* Wait for 500 ms. */\n    }\n}\n```\n\n# Licensing\n\nBrook4-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.\n\n[![GNU Lesser General Public License v3.0](https://www.gnu.org/graphics/lgplv3-88x31.png)](https://www.gnu.org/licenses/lgpl-3.0.html)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frisoflora%2Fbrook4xc8","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frisoflora%2Fbrook4xc8","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frisoflora%2Fbrook4xc8/lists"}