libmmb103.h

00001 /*
00002 # This file is Copyright 2006, 2007, 2009 Dean Hall.
00003 #
00004 # This file is part of the Python-on-a-Chip program.
00005 # Python-on-a-Chip is free software: you can redistribute it and/or modify
00006 # it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1.
00007 # 
00008 # Python-on-a-Chip is distributed in the hope that it will be useful,
00009 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00011 # A copy of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1
00012 # is seen in the file COPYING up one directory from this.
00013 */
00014 
00015 
00016 #ifndef __LIBMMB103_H__
00017 #define __LIBMMB103_H__
00018 
00019 
00020 /*
00021  * MMB103 Library Header
00022  */
00023 
00024 
00026 #define MMB103_v1j 1       
00027 #define MMB103_v1m 2       
00030 #define MMB103_VER MMB103_v1m
00031 
00033 #define DIG_LATCH (*(volatile uint8_t *)0xB800)
00034 
00036 #define DIP_LATCH (*(volatile uint8_t *)0xA800)
00037 
00043 #define BAUD_2400 103
00044 #define BAUD_4800 51
00045 #define BAUD_9600 25
00046 #define BAUD_14400 16
00047 #define BAUD_19200 12
00048 #define BAUD_28800 8
00049 #define BAUD_38400 6
00050 #define BAUD_57600 3
00051 #define BAUD_76800 2
00052 #define BAUD_115200 1
00053 
00067 #define ADC_STOP            0
00068 #define ADC_CK_DIV_2        (_BV(ADPS0))
00069 #define ADC_CK_DIV_4        (_BV(ADPS1))
00070 #define ADC_CK_DIV_8        (_BV(ADPS1) | _BV(ADPS0))
00071 #define ADC_CK_DIV_16       (_BV(ADPS2))
00072 #define ADC_CK_DIV_32       (_BV(ADPS2) | _BV(ADPS0))
00073 #define ADC_CK_DIV_64       (_BV(ADPS2) | _BV(ADPS1))
00074 #define ADC_CK_DIV_128      (_BV(ADPS2) | _BV(ADPS1) | _BV(ADPS0)) /* 2Ksps */
00075 
00093 #define PWM_STOP            0
00094 #define PWM_CK_DIV_1        _BV(CS10)                /* 15 KHz */
00095 #define PWM_CK_DIV_8        _BV(CS11)                /* 2 KHz  */
00096 #define PWM_CK_DIV_64       (_BV(CS11) | _BV(CS10))   /* 244 Hz */
00097 #define PWM_CK_DIV_256      _BV(CS12)
00098 #define PWM_CK_DIV_1024     (_BV(CS12) | _BV(CS10))
00099 
00100 
00101 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
00102 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
00103 
00105 /* LCD ctl pins, grouped by fxn */
00106 #define LCD_CLS             0x01
00107 #define LCD_HOME            0x02
00108 /* entry mode set */
00109 #define LCD_ENTRY           0x04
00110 #define LCD_ENTRY_CURS_INCR 0x02
00111 #define LCD_ENTRY_DISP_SHFT 0x01
00112 /* display ctl */
00113 #define LCD_DISP            0x08
00114 #define LCD_DISP_DISP_ON    0x04
00115 #define LCD_DISP_CURS_BLOCK 0x03
00116 #define LCD_DISP_CURS_ULINE 0x02
00117 #define LCD_DISP_CURS_BLINK 0x01
00118 /* cursor/display shift */
00119 #define LCD_CURS            0x10
00120 #define LCD_CURS_DISP_SHFT  0x08
00121 #define LCD_CURS_SHFT_R     0x04
00122 /* function set */
00123 #define LCD_FUNC            0x20
00124 #define LCD_FUNC_8B_DATA    0x10
00125 #define LCD_FUNC_MULTI_LINE 0x08
00126 #define LCD_FUNC_FONT_5x10  0x04    /* no effect */
00127 /* set CGRAM addr */
00128 #define LCD_CGRAM(n)        (0x40 + ((n) << 3))
00129 /* set DDRAM addr */
00130 /* these might not work for 4 line displays */
00131 #define LCD_CURSOR(n)       (0x80 + ((n) & 0x7f))
00132 #define LCD_LINE(n)         LCD_CURSOR(((n) & 0x02) ? 0x20 : 0x00 \
00133                                        + ((n) & 0x01) ? 0x40 : 0x00)
00134 /* LCD mini-macros */
00135 #define LCD_ENTRY_DECR      (LCD_ENTRY)
00136 #define LCD_ENTRY_INCR      (LCD_ENTRY | LCD_ENTRY_CURS_INCR)
00137 #define LCD_DISP_OFF        (LCD_DISP)
00138 #define LCD_DISP_ON         (LCD_DISP | LCD_DISP_DISP_ON)
00139 #define LCD_CURS_ULINE      (LCD_DISP | LCD_DISP_DISP_ON | LCD_DISP_CURS_ULINE)
00140 #define LCD_CURS_BLOCK      (LCD_DISP | LCD_DISP_DISP_ON | LCD_DISP_CURS_BLOCK)
00141 #define LCD_CURS_BLINK      /*TBD*/
00142 #define LCD_CURS_LEFT       (LCD_CURS)
00143 #define LCD_CURS_RIGHT      (LCD_CURS | LCD_CURS_SHFT_R)
00144 #define LCD_DISP_LEFT       (LCD_CURS | LCD_CURS_DISP_SHFT)
00145 #define LCD_DISP_RIGHT      (LCD_CURS | LCD_CURS_DISP_SHFT | LCD_CURS_SHFT_R)
00146 #define LCD_MODE_MULTILINE  (LCD_FUNC | LCD_FUNC_8B_DATA | LCD_FUNC_MULTI_LINE)
00147 
00148 
00161 void mmb_init(uint8_t uart_rate,
00162               uint8_t adc_rate,
00163               uint8_t pwm_rate,
00164               uint8_t num_lcd_lines,
00165               uint8_t num_lcd_cols);
00166 
00173 uint8_t mmb_adc_get(uint8_t ch);
00174 
00181 #define mmb_dig_get(p) (uint8_t)((DIG_LATCH & _BV(p)) ? 1 : 0)
00182 
00184 #define mmb_dig_get_byte() (DIG_LATCH)
00185 
00194 #define mmb_dip_get(p) (uint8_t)((DIP_LATCH & _BV(p)) ? 1 : 0)
00195 
00197 #define mmb_dip_get_byte() (DIP_LATCH)
00198 
00200 void mmb_spi_init(uint8_t spi_rate);
00201 
00208 uint8_t mmb_spiGetByte(void);
00209 
00215 void mmb_spiPutByte(uint8_t c);
00216 
00225 uint8_t mmb_spiGetByteN(uint8_t *p, uint8_t n);
00226 
00234 void mmb_spiPutByteN(uint8_t *p, uint8_t n);
00235 
00240 void mmb_lcd_clr_scr(void);
00241 
00242 
00249 void mmb_lcd_set_cursor(uint8_t line, uint8_t col);
00250 
00251 
00258 void mmb_lcd_print_char(uint8_t ch);
00259 
00269 void mmb_lcd_print_str(char *s);
00270 
00276 void mmb_lcd_print_hex8(uint8_t v8);
00277 
00283 void mmb_lcd_print_hex16(uint16_t v16);
00284 
00291 void mmb_lcd_put_ctl(uint8_t val);
00292 
00294 void mmb_lcd_title_screen(void);
00295 
00304 void mmb_set_mota_pwm(int16_t dc_10bit);
00305 
00314 void mmb_set_motb_pwm(int16_t dc_10bit);
00315 
00317 void mmb_motc_init(void);
00318 
00320 void mmb_set_motc_pwm(uint8_t dc_8b);
00321 
00331 void mmb_beep(int16_t freq, int16_t ms);
00332 
00334 void mmb_servo_init(uint8_t enable);
00335 
00341 void mmb_set_servo_a(int8_t pos);
00342 
00348 void mmb_set_servo_b(int8_t pos);
00349 
00350 #endif /* __LIBMMB103_H__ */

Generated on Wed Feb 24 13:37:02 2010 for Python-on-a-chip by  doxygen 1.5.9