msc1210 (ainterrupt) applications useing ulan (needs higher extra stack).
)FI
PUBLIC VEC_SET,VEC_USR,VEC_GET
+EXTRN CODE(_SETUP_BOARD)
%IF(%FOR_SDCC)THEN(
PUBLIC __SDCC_EXTERNAL_STARTUP
CALL SRETI
CALL SRETI
CALL SRETI
+ CALL _SETUP_BOARD
MOV DPL,#0
RET
SRETI: RETI
%DEFINE (SPN) (1) ; Cislo serioveho portu
-SER_STACK_EXT EQU 0 ; Pridavna hodnota pro stack
+SER_STACK_EXT EQU 5+2 ; Pridavna hodnota pro stack - ainterrupts + 2 bytes extra
END_RAM XDATA 08800H ; Konec pameti
LENG_IB EQU 1 ; Delka vstupniho bufferu v 256 bytu
# -*- makefile -*-
-SUBDIRS = flash
+SUBDIRS = flash adc
--- /dev/null
+# Generic directory or leaf node makefile for OCERA make framework
+
+ifndef MAKERULES_DIR
+MAKERULES_DIR := $(shell ( old_pwd="" ; while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" == `pwd` ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) )
+endif
+
+ifeq ($(MAKERULES_DIR),)
+all : default
+.DEFAULT::
+ @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+else
+include $(MAKERULES_DIR)/Makefile.rules
+endif
+
--- /dev/null
+# -*- makefile -*-
+
+include_HEADERS = msc_adc.h
+
+lib_LIBRARIES = msc_adc
+
+msc_adc_SOURCES = msc_adc.c
\ No newline at end of file
--- /dev/null
+#include <system_def.h>
+#include <cpu_def.h>
+
+bit
+msc_adc_ready(void) {
+ return AIE&0x20;
+}
+
+
+long
+msc_adc_unipolar(void) {
+ _asm
+ mov a,#0
+ mov b,_ADRESH
+ mov dph,_ADRESM
+ mov dpl,_ADRESL
+ _endasm;
+
+/* #pragma asm
+ mov r4,#0
+ mov r5,ADRESH
+ mov r6,ADRESM
+ mov r7,ADRESL
+ #pragma endasm*/
+}
+
+
+long
+msc_adc_bipolar(void) {
+/* #pragma asm
+ mov a,ADRESH
+ mov r5,a
+ mov c,acc.7
+ subb a,acc
+ mov r4,a
+ mov r6,ADRESM
+ mov r7,ADRESL
+ #pragma endasm*/
+}
+
+long
+msc_adc_summer(void) {
+/* #pragma asm
+ mov r4,SUMR3
+ mov r5,SUMR2
+ mov r6,SUMR1
+ mov r7,SUMR0
+ #pragma endasm*/
+}
+
+
+void
+msc_adc_set_input(unsigned char admux) {
+ // 7 6 5 4 3 2 1 0
+ // ADCON1 - POL SM1 SM0 - CAL2 CAL1 CAL0
+ ADMUX = admux;
+}
+
+int
+msc_adc_init(void) {
+ PDCON &= 0xf7; //turn on adc
+ // ACLK min 32
+ ACLK = 15; // ACLK = 18.432MHz/(1+1)= 0.9216MHz
+
+ // max 2047 // Data Rate = (ACLK + 1)/64/DECIMATION
+// DECIMATION = 1080; // Data Rate = 18.432/2/64/14400 = 10.00Hz
+ ADCON2=1080%256;
+ ADCON3=1080/256;
+
+ // 7 6 5 4 3 2 1 0
+ // ADCON0 - BOD EVREF VREFH EBUF PGA2 PGA1 PGA0
+ ADCON0 = 0x30; // Vref on 2.5V, Buff on, BOD off, PGA 1
+
+ // 7 6 5 4 3 2 1 0
+ // ADCON1 - POL SM1 SM0 - CAL2 CAL1 CAL0
+ ADCON1 = 0x01; // bipolar, auto, self calibration, offset
+ return 0;
+}
--- /dev/null
+#ifndef _MSC_ADC_H
+#define _MSC_ADC_H
+
+#include <types.h>
+
+#define MSC_ADC_LSB_BIPOLAR 298.0232e-9
+#define MSC_ADC_V2T_INTERNAL(x) (2664.7*(x)-282.14)
+
+typedef struct msc_adc_input {
+ uint8_t ain; //input
+ float avg_value; //avg value
+ uint8_t samples; //period per avg value
+ uint8_t samples_cnt; //counter period per avg value
+ uint8_t calibration;
+ } msc_adc_input_t;
+
+typedef struct msc_adc_input_list {
+ uint8_t count;
+ int8_t capacity;
+ msc_adc_input_t **inputs;
+ uint8_t input_position;
+ } msc_adc_input_list_t;
+
+bit msc_adc_ready(void);
+int msc_adc_init(void);
+void msc_adc_set_input(unsigned char admux);
+long msc_adc_unipolar(void);
+
+#endif /* _MSC_ADC_H */
CONFIG_ULAN=y
CONFIG_MISC_VECT=y
CONFIG_ULOI_LT=y
+
+CONFIG_MSC_ADC=y
--- /dev/null
+# -*- makefile -*-
+
+APP=weather-station
+
+ARCH=mcs51
+MACH=msc1210
+BOARD=hisc
+
+ULAN_ID=$(APP)-$(BOARD)
+ULAN_CFG=$(BOARD)
+
+TARGET_ARCH = -mmcs51 --model-large
+
+CONFIG_APP_HISC_WEATHER_STATION=y
+
+CONFIG_ULAN=y
+CONFIG_MISC_VECT=y
+CONFIG_ULOI_LT=y
+
+CONFIG_MSC_ADC=y
# -*- makefile -*-
lib_LDSCRIPTS = $(notdir $(wildcard $(SOURCES_DIR)/*.ld*))
+
+SUBDIRS = bspbase
\ No newline at end of file
--- /dev/null
+# Generic directory or leaf node makefile for OCERA make framework
+
+ifndef MAKERULES_DIR
+MAKERULES_DIR := $(shell ( old_pwd="" ; while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" == `pwd` ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) )
+endif
+
+ifeq ($(MAKERULES_DIR),)
+all : default
+.DEFAULT::
+ @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+else
+include $(MAKERULES_DIR)/Makefile.rules
+endif
+
--- /dev/null
+# -*- makefile -*-
+
+include_HEADERS = bspbase.h
+
+lib_LIBRARIES = bspbase
+
+bspbase_SOURCES = bsp0hwinit.c
+
+ifeq ($(CONFIG_MSC_ADC),y)
+CFLAGS += -DMSC_ADC_ENABLED
+endif
\ No newline at end of file
--- /dev/null
+#include <bspbase.h>
+#include <vect.h>
+#include <msc_adc.h>
+
+//timers
+uint8_t DATA t100ms;
+bit t100ms_flg;
+
+/****************************************************************************/
+//definice pruseni (casovac)
+
+void ainterrupts(void) interrupt {
+ uint8_t data aie=AIE;
+
+ if (aie & 0x10) {
+ uint8_t msint=MSINT;
+
+ /* timer */
+ if (t100ms==10) {
+ t100ms=0;
+ t100ms_flg=1;
+ } else t100ms++;
+
+ #ifdef WATCHDOG_ENABLED
+ WATCHDOG_REFRESH();
+ #endif
+ }
+ AI=0; // Clear Aux INT (Bit in EICON)
+}
+
+/****************************************************************************/
+void setup_board(void)
+{
+ MCON|=1; //XDATA memory map to 0x8400
+
+ his_out_putb(0xff);
+
+ MSECH=(CPU_SYS_HZ/1000-1) / 0x100;
+ MSECL=(CPU_SYS_HZ/1000-1) % 0x100;
+ PDCON&=~0x02; // System Timer ON
+ MSINT=9|128; //10ms
+ vec_set(ainterrupts,0x33);
+ AIE=0x10;
+
+#ifdef MSC_ADC_ENABLED
+ msc_adc_init();
+#endif
+
+ //********************
+ // watchdog
+#ifdef WATCHDOG_ENABLED
+ WATCHDOG_ON();
+ WATCHDOG_SET_MS(1000); //1s
+#endif
+
+}
--- /dev/null
+#ifndef _BSPBASE_H
+#define _BSPBASE_H
+
+#include <types.h>
+#include <system_def.h>
+#include <cpu_def.h>
+
+//timers
+extern uint8_t DATA t100ms;
+extern bit t100ms_flg;
+
+#endif /* _BSPBASE_H */