From f6e01a29448d98177b43556a79d574f42a7b4072 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Tue, 23 Aug 2016 23:46:43 +0200 Subject: LCD working; simple test --- firmware/main.c | 121 ++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 79 insertions(+), 42 deletions(-) (limited to 'firmware/main.c') diff --git a/firmware/main.c b/firmware/main.c index d85cfe1..d03b3e2 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -1,52 +1,89 @@ #include -#include "t6963c_specific.h" + +#include "init.h" + #include "t6963c/t6963c.h" +#include "t6963c/terminal.h" + +static Terminal* term; -// CONFIG1 -#pragma config WPCFG = WPCFGDIS // Write Protect Configuration Page Select->Last page (at the top of program memory) and Flash Configuration Words are not write-protected -#pragma config WPDIS = WPDIS // Segment Write Protection Disable->Segmented code protection is disabled -#pragma config WPFP = WPFP255 // Write Protection Flash Page Segment Boundary->Highest Page (same as page 170) -#pragma config SOSCSEL = EC // Secondary Oscillator Power Mode Select->External clock (SCLKI) or Digital I/O mode( -#pragma config ALTPMP = ALPMPDIS // Alternate PMP Pin Mapping->EPMP pins are in default location mode -#pragma config WPEND = WPENDMEM // Segment Write Protection End Page Select->Protected code segment upper boundary is at the last page of program memory; the lower boundary is the code page specified by WPFP -#pragma config WUTSEL = LEG // Voltage Regulator Wake-up Time Select->Default regulator start-up time is used - -// CONFIG2 -#pragma config POSCMOD = NONE // Primary Oscillator Select->Primary oscillator is disabled -#pragma config FCKSM = CSDCMD // Clock Switching and Fail-Safe Clock Monitor->Clock switching and Fail-Safe Clock Monitor are disabled -#pragma config OSCIOFNC = ON // OSCO Pin Configuration->OSCO/CLKO/RC15 functions as port I/O (RC15) -#pragma config PLL96MHZ = ON // 96MHz PLL Startup Select->96 MHz PLL is enabled automatically on start-up -#pragma config PLLDIV = NODIV // 96 MHz PLL Prescaler Select->Oscillator input is used directly (4 MHz input) -#pragma config IOL1WAY = ON // IOLOCK One-Way Set Enable->The IOLOCK bit (OSCCON<6>) can be set once, provided the unlock sequence has been completed. Once set, the Peripheral Pin Select registers cannot be written to a second time. -#pragma config FNOSC = FRCPLL // Initial Oscillator Select->Fast RC Oscillator with Postscaler and PLL module (FRCPLL) -#pragma config IESO = ON // Internal External Switchover->IESO mode (Two-Speed Start-up) is enabled - -// CONFIG1 -#pragma config WDTPS = PS32768 // Watchdog Timer Postscaler->1:32,768 -#pragma config GCP = OFF // General Segment Code Protect->Code protection is disabled -#pragma config FWDTEN = OFF // Watchdog Timer->Watchdog Timer is disabled -#pragma config ICS = PGx1 // Emulator Pin Placement Select bits->Emulator functions are shared with PGEC1/PGED1 -#pragma config WINDIS = OFF // Windowed WDT->Standard Watchdog Timer enabled,(Windowed-mode is disabled) -#pragma config JTAGEN = OFF // JTAG Port Enable->JTAG port is disabled -#pragma config FWPSA = PR128 // WDT Prescaler->Prescaler ratio of 1:128 -#pragma config GWRP = OFF // General Segment Write Protect->Writes to program memory are allowed - -void init(void) { - // CPDIV 1:1; RCDIV FRC/2; DOZE 1:8; G1CLKSEL disabled; DOZEN disabled; ROI disabled; - CLKDIV = 0x3100; - // GCLKDIV 1; - CLKDIV2 = 0x0000; - - t6963c_init(); +//unsigned char* string = "me@pic:~$ ls +//me@pic:~$ mkdir docs +//me@pic:~$ cd docs/ +//me@pic:~/docs$ ls +//me@pic:~/docs$ touch doc.txt +//me@pic:~/docs$ ls +//doc.txt +//me@pic:~/docs$ cat doc.txt +//me@pic:~/docs$ echo hello > doc.txt +//me@pic:~/docs$ cat doc.txt +//hello +//me@pic:~/docs$ cd .. +//me@pic:~$ tree -fFi +//. +//./docs/ +//./docs/doc.txt +// +//1 directory, 1 file +//me@pic:~$ rm -r docs/ +//"; +const static char* string = + "[me@pic ~] ls\n" + "[me@pic ~] mkdir docs\n" + "[me@pic ~] cd docs/\n" + "[me@pic docs] ls\n" + "[me@pic docs] touch doc.txt\n" + "[me@pic docs] ls\n" + "doc.txt\n" + "[me@pic docs] cat doc.txt\n" + "[me@pic docs] echo hello > doc.txt\n" + "[me@pic docs] cat doc.txt\n" + "hello\n" + "[me@pic docs] cd ..\n" + "[me@pic ~] tree -fFi\n" + ".\n" + "./docs/\n" + "./docs/doc.txt\n" + "\n" + "1 directory, 1 file\n" + "[me@pic ~] rm -r docs/\n"; + +void init_terminal(void) { + term = terminal.construct(t6963c_rows * t6963c_columns); + term->update = t6963c_update_terminal; +} + +void loop_string(void) { + unsigned short i, j; + unsigned char state = 0; // 0 = quick, 1 = slow + for (i = 0; string[i]; i++) { + if (!terminal.appendChar(term, string[i])) { + terminal.free(term); + t6963c_clear(); + t6963c_set_address(5,5); + t6963c_writeString("ERROR"); + while (1); + } + if (string[i] == ']') { + state = 1; + terminal.appendChar(term, string[++i]); + __delay_ms(800); + } else if (string[i] == '\n') { + state = 0; + } + if (state) { + __delay_ms(80); + } + } } int main(void) { - TRISBbits.TRISB0 = 0; + init(); + init_terminal(); + while (1) { - delay_ns(1000); - LATBbits.LATB0 = 0; - delay_ns(100); - LATBbits.LATB0 = 1; + loop_string(); } + return 0; } -- cgit v1.2.3