diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-24 18:42:24 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-24 18:42:24 +0000 |
commit | f508189682b6fba62e08feeb1596f682bad5fff9 (patch) | |
tree | 28aeb0e6c19386c385c1ce5edf8a92c1bca15281 /test/sdcc18 | |
download | piklab-f508189682b6fba62e08feeb1596f682bad5fff9.tar.gz piklab-f508189682b6fba62e08feeb1596f682bad5fff9.zip |
Added KDE3 version of PikLab
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/piklab@1095639 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'test/sdcc18')
-rw-r--r-- | test/sdcc18/test18.c | 14 | ||||
-rw-r--r-- | test/sdcc18/test18.piklab | 17 | ||||
-rw-r--r-- | test/sdcc18/usart_test.c | 105 | ||||
-rw-r--r-- | test/sdcc18/usart_test.piklab | 51 |
4 files changed, 187 insertions, 0 deletions
diff --git a/test/sdcc18/test18.c b/test/sdcc18/test18.c new file mode 100644 index 0000000..00dc375 --- /dev/null +++ b/test/sdcc18/test18.c @@ -0,0 +1,14 @@ +#include <pic18f452.h> + +void main(void) +{ + float f = TRISA; + int a = TRISB; + LATA = 0xFF; + LATAbits.LATA1 = 0; +// UIE = 0x55; + f /= a; + a = f; + TRISA = a; + while(1); +} diff --git a/test/sdcc18/test18.piklab b/test/sdcc18/test18.piklab new file mode 100644 index 0000000..d9e688d --- /dev/null +++ b/test/sdcc18/test18.piklab @@ -0,0 +1,17 @@ +<!DOCTYPE piklab> +<piklab> + <general> + <device>18F452</device> + <tool>sdcc</tool> + <files> + <item>test18.c</item> + </files> + <opened_files> + <item>test18.c</item> + </opened_files> + <watched_registers> + <item>0 2 </item> + </watched_registers> + </general> + <editors/> +</piklab> diff --git a/test/sdcc18/usart_test.c b/test/sdcc18/usart_test.c new file mode 100644 index 0000000..1b611d9 --- /dev/null +++ b/test/sdcc18/usart_test.c @@ -0,0 +1,105 @@ +// read and write eeprom of PIC18F2550 (and 18F2455, 18F4455, 18F4550) +// EEPROM size is 256 bytes +// (c) Raphael Wimmer. Licensed under GNU GPL v2 or higher +#include <pic18f452.h> +//#include <pic18fregs.h> +#include <stdio.h> +#include <usart.h> +#include <adc.h> + +code char at __CONFIG1H config1h = 0xFF & _OSC_XT_1H & _OSCS_OFF_1H; +code char at __CONFIG2L config2l = 0xFF & _PUT_ON_2L & _BODEN_OFF_2L & _BODENV_2_7V_2L; +code char at __CONFIG2H config2h = 0xFF & _WDT_OFF_2H; +code char at __CONFIG3H config3h = 0xFF & _CCP2MUX_RC1_3H; +code char at __CONFIG4L config4l = 0xFF & _LVP_OFF_4L & _BACKBUG_ON_4L & _STVR_OFF_4L; +code char at __CONFIG5L config5l = 0xFF & _CP_0_OFF_5L & _CP_1_OFF_5L; +code char at __CONFIG5H config5h = 0xFF & _CPD_OFF_5H & _CPB_OFF_5H; +code char at __CONFIG6L config6l = 0xFF & _WRT_0_OFF_6L & _WRT_1_OFF_6L; +code char at __CONFIG6H config6h = 0xFF & _WRTD_OFF_6H & _WRTB_OFF_6H & _WRTC_OFF_6H; +code char at __CONFIG7L config7l = 0xFF & _EBTR_0_OFF_7L & _EBTR_1_OFF_7L; +code char at __CONFIG7H config7h = 0xFF & _EBTRB_OFF_7H; + +#pragma stack 0x300 0xff // set 64 byte stack at 0x300, needed by sdcc + +static void isr(void) interrupt 1 { +/* +n Interrupt Vector Interrupt Vector Address +0 RESET vector 0x000000 +1 HIGH priority interrupts 0x000008 +2 LOW priority interrupts 0x000018 +*/ +} + +void ee_write_byte(unsigned char address, unsigned char *_data){ + + EEDATA = *_data; + EEADR = address; + // start write sequence as described in datasheet, page 91 + EECON1bits.EEPGD = 0; + EECON1bits.CFGS = 0; + EECON1bits.WREN = 1; // enable writes to data EEPROM + INTCONbits.GIE = 0; // disable interrupts + EECON2 = 0x55; + EECON2 = 0x0AA; + EECON1bits.WR = 1; // start writing + while(EECON1bits.WR){ + _asm nop _endasm;} + if(EECON1bits.WRERR){ + // printf("ERROR: writing to EEPROM failed!\n"); + } + EECON1bits.WREN = 0; + INTCONbits.GIE = 1; // enable interrupts +} + +void adc_start() { + + adc_open(ADC_CHN_1, ADC_FOSC_4, ADC_CFG_5A_0R, ADC_FRM_RJUST); + while (adc_busy()) ; + adc_read(); +//unsigned char channel, unsigned char fosc, unsigned char pcfg, unsigned char config + +} + +void ee_read_byte(unsigned char address, unsigned char *_data){ + EEADR = address; + EECON1bits.CFGS = 0; + EECON1bits.EEPGD = 0; + EECON1bits.RD = 1; + *_data = EEDATA; +} + +void initUsart() +{ + usart_open( // Use USART library to initialise the hardware + USART_TX_INT_OFF + & USART_RX_INT_OFF + & USART_BRGH_HIGH + & USART_ASYNCH_MODE + & USART_EIGHT_BIT, + 10 // '10' = 115200 Baud with 20 MHz oscillator and BRGH=1 + ); + stdout = STREAM_USART; +} + + + +// very simple example. use on an erased eeprom + +void main(){ + + char save_me = 'c'; + char from_eeprom; + adc_start(); + initUsart(); + + printf("E"); + ee_read_byte(0x00, &from_eeprom); + printf("%c", from_eeprom); + + ee_write_byte(0x00, &save_me); + printf("%c", save_me); + + ee_read_byte(0x00, &from_eeprom); + printf("%c", from_eeprom); +while (1){} +} diff --git a/test/sdcc18/usart_test.piklab b/test/sdcc18/usart_test.piklab new file mode 100644 index 0000000..71da3cf --- /dev/null +++ b/test/sdcc18/usart_test.piklab @@ -0,0 +1,51 @@ +<!DOCTYPE piklab> +<piklab> + <general> + <device>18F452</device> + <tool>sdcc</tool> + <files> + <item>usart_test.c</item> + <item>/usr/share/sdcc/lib/pic16/libio18f452.lib</item> + <item>/usr/share/sdcc/lib/pic16/libc18f.lib</item> + </files> + <description/> + <version>0.1</version> + </general> + <compiler> + <has_custom_arguments>false</has_custom_arguments> + <custom_options/> + <custom_arguments> + <item>-m%FAMILY</item> + <item>-%DEVICE</item> + <item>-V</item> + <item>--debug</item> + <item>-I$(SRCPATH)</item> + <item>-c</item> + <item>%I</item> + </custom_arguments> + <includes> + <item>$(SRCPATH)</item> + </includes> + </compiler> + <linker> + <has_custom_arguments>false</has_custom_arguments> + <custom_options/> + <format>inhx32</format> + <custom_arguments> + <item>-m%FAMILY</item> + <item>-%DEVICE</item> + <item>-V</item> + <item>--debug</item> + <item>-Wl-c</item> + <item>$LKR(-Wl-s%LKR)</item> + <item>-I$(SRCPATH)</item> + <item>-o%O</item> + <item>%OBJS</item> + <item>%LIBS</item> + </custom_arguments> + <includes> + <item>$(SRCPATH)</item> + </includes> + </linker> + <editors/> +</piklab> |