PIC is a native compiler for 8-bit PIC micro controllers written in Common Lisp. The host language is a pretty small subset of ML-like language and the target language is 8-bit PIC micro controller assembly. Common Lisp is the compiler language.
Usage
Following is an example of LED blinking with PIC12F683 micro controller. init function is one of the compiler's special functions, where the micro controller's SFR(Special Function Registers) are initialized. Following main function is also the compiler's special function and program's main routine is executed here.mdelay1 function and mdelay macro are for delaying. Note that since 8-bit PIC handles only 8-bit unsigned integers, nested loops are needed for delaying more than 255 msec (950 msec here). progn and loop are predefined macros for the compiler.
(defpic init () (progn (setreg :gpio #x0) ; clera GP0-5 (setreg :cmcon0 #x07) ; disable comparator (setbank1) ; switch to bank 1 (setreg :trisio #x08) ; only GP3 is outputinputmode (setreg :ansel #x00) ; disable analog IO (setreg :ioc #x00) ; disable interruption (setbank0) ; switch to bank 0 (setreg :intcon #x00))) ; disable interruption (defpic main () (progn (setreg :gpio #x20) ; set GP5 to high (mdelay 50) ; delay for 50 msec (setreg :gpio #x00) ; set GP5 to low (mdelay 950) ; delay for 950 msec (main))) ; repeat (defpic mdelay1 () (loop 90 ; 90 is a magic number to delay 0)) ; for 1 msec (defpicmacro mdelay (n) (unless (<= 0 n 65535) (error "The value ~S is invalid." n)) (multiple-value-bind (q r) (truncate n 256) (if (= q 0) `(loop ,r (mdelay1)) `(loop ,q (loop ,r (mdelay1))))))Then pic-compile function compiles and outputs the complete assembly for the PIC functions to standard output. The output assembly is expected to be assembled with Microchip's MPASM assembler.
PIC> (pic-compile) INCLUDE"p12f683.inc" list p=12f683 __CONFIG _CP_OFF & _CPD_OFF & _WDT_OFF & _BOD_ON & _IESO_OFF& _PWRTE_ON & _INTOSCIO & _MCLRE_OFF CBLOCK 020h L0,L1,L2,L3,L4,L5,L6,L7 ; local registers I0,I1,I2,I3,I4,I5,I6,I7 ; input registers SP,STMP,STK ; stack registers ENDC ORG 0 GOTO MAIN ... END ; No valueFor detail, please see its repository.
0 件のコメント:
コメントを投稿