first off greetings, been a long time lurker here, can't even remember the number of times posts from this forum has saved me, usually when I'm stuck a quick search get's me unstuck with ease... so thank you everyone.
now for the stuck part...
I've been using Darryl's awesome MIBAM with a 12F683 for some time, just
some fading rgb led's etc.. nothing fancy, everything works great...
enter the 12F1822, was hoping to eventually utilize the hardware EUSART to send rgb color data to each led, since using MIBAM pretty much rules out any software serial communication on the 683. (and not quite sure when the 12F1501 will be available with 4xPWM)
So before I go any further I wanted to just setup a simple test program to make sure things in general are working..
here's how the pic is wired up..
here is my code for basic testing
Code:
'****************************************************************
' MIBAM TEST pic12F683 / pic12f1822 *
'****************************************************************
#IF __PROCESSOR__ = "12F1822"
#MSG "Compililng for 12F1822..."
#CONFIG
__config _CONFIG1, _FOSC_INTOSC & _MCLRE_OFF
__config _CONFIG2, _PLLEN_OFF & _LVP_OFF
#ENDCONFIG
OSCCON = %01110000 '8mhz
TRISA = %00011000 'setup inputs/outputs
ANSELA = %00010000 'RA4 = analog
CM1CON0 = 0 'disable comarators
ADCON0 = %00001101 'Select AN3 enable ADC
ADCON1 = %11010000 'Right Justify - Fosc/16 & 8mhz
#ELSE
#if __PROCESSOR__ = "12F683"
#msg "Compiling for 12F683..."
#CONFIG
__config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF
#ENDCONFIG
OSCCON = %01110001 '8mhz
TRISIO = %00011000 'setup inputs/outputs
ANSEL = %01011000 'RA4 = analog
CMCON0 = %00000111 'disable comarators
ADCON0 = %10001101 'Right Justify - Fosc/16 & 8mhz
#else
#ERROR "Only 12F1822 & 12F683 are supported!"
#endif
#ENDIF
DEFINE OSC 8 '8mhz
DEFINE ADC_BITS 10 '10 bit ADC
DEFINE DEBUG_REG PORTA
DEFINE DEBUG_BIT 5
DEFINE DEBUG_BAUD 9600
DEFINE DEBUG_MODE 0
;____[ For 12F/16F only - Interrupt Context save locations]_________________
wsave var byte $20 SYSTEM ' location for W if in bank0
;wsave var byte $70 SYSTEM ' Alternate save location for W
' if using $70, comment out wsave1-3
' --- IF any of these next three lines cause an error ?? -------------------
' Comment them out to fix the problem ----
' -- The chip being used determines which variables are needed -------------
wsave1 VAR BYTE $A0 SYSTEM ' location for W if in bank1
'wsave2 VAR BYTE $120 SYSTEM ' location for W if in bank2
'wsave3 VAR BYTE $1A0 SYSTEM ' location for W if in bank3
'---DO NOT change these-----------------------------------------------------
ssave VAR BYTE BANK0 SYSTEM ' location for STATUS register
psave VAR BYTE BANK0 SYSTEM ' location for PCLATH register
;----[ MIBAM Setup ]--------------------------------------------------------
BAM_COUNT CON 3 ; How many BAM Pins are used?
INCLUDE "MIBAM.pbp" ; Mirror Image BAM module
RED VAR BYTE
GRN VAR BYTE
BLU VAR BYTE
adc_val var word 'adc value variable
adc_thresh var word 'adc trigger threshold variable
ASM
BAM_LIST macro ; Define PIN's to use for BAM
BAM_PIN (PORTA,0, BLU) ; and the associated Duty variables
BAM_PIN (PORTA,1, RED)
BAM_PIN (PORTA,2, GRN)
endm
BAM_INIT BAM_LIST ; Initialize the Pins
ENDASM
Speed CON 5 'led fade speed
adc_thresh = 300 'trigger threshold
red = 0
blu = 0
grn = 0
T1CON.0 = 0 'disable mibam
debug "Program Start..",13,10
pause 2
T1CON.0 = 1 'enable mibam
'test MIBAM turn on and fade each led
FOR red = 255 to 1 STEP -1
PAUSE Speed
NEXT red
red = 0
FOR grn = 255 to 1 STEP -1
PAUSE Speed
NEXT grn
grn = 0
FOR BLU = 255 to 1 STEP -1
PAUSE Speed
NEXT BLu
blu = 0
'------------------------ MAIN PROGRAM LOOP ------------------------
main:
gosub do_adc 'get ADC reading
pause 20
T1CON.0 = 0 'disable mibam
debug "ADC: ",dec4 adc_val,13,10
pause 2
T1CON.0 = 1 'enable mibam
if adc_val > adc_thresh then
FOR red = 255 to 1 STEP -1
PAUSE Speed
NEXT red
red = 0
FOR grn = 255 to 1 STEP -1
PAUSE Speed
NEXT grn
grn = 0
FOR BLU = 255 to 1 STEP -1
PAUSE Speed
NEXT BLu
blu = 0
endif
goto main
'----------------------------------------------------------------------
Do_Adc:
pauseus 50
ADCON0.1=1
WHILE ADCON0.1 : WEND
adc_val.highbyte = ADRESH
adc_val.lowbyte = ADRESL
return
when compiled for 12F683, everything works fine... the test program does.
1. debug output --> "Program Start..."
2. lights up and fades each led r/g/b
3. debug output ADC reading
4. waits for ADC threshold to >300 then triggers the light sequence again.
now when I first compiled for 12F1822 I was greeted with the following error
Code:
PICBASIC PRO(TM) Compiler 3.0.0.4, (c) 1998, 2011 microEngineering Labs, Inc.
All Rights Reserved.
[MESSAGE] ledtest.pbp(13): Compililng for 12F1822...
[ASM ERROR] LEDTEST.ASM (451) : Illegal opcode (_CylonMask)
[ASM WARNING] LEDTEST.ASM (451) : Found label after column 1. (rrcf)
[ASM ERROR] LEDTEST.ASM (459) : Illegal opcode (_CylonMask)
[ASM WARNING] LEDTEST.ASM (459) : Found label after column 1. (rlcf)
[ASM WARNING] LEDTEST.ASM (547) : Extraneous arguments on the line
not being one to give up so fast... started to track down what is causing the error message... discovered the following in MIBAM.bas.
Code:
;----[ makes rrf work on 18F's ]--------------------------------------------
ASM nolist
ifdef BSR
#define rrf rrcf
#define rlf rlcf
endif
list ENDASM
if I comment out the #define's the program does compile successfully however mibam begins to work correctly and then stops working. The following happens.
1. debug output --> "Program Start..."
2. lights up and fades each led r/g/b
3. debug output ADC reading
4. waits for ADC threshold to >300 *FAILS* to tigger the light sequence.
basically you can see that the loops are running due to the pause in debug output but the leds now stay off...
I am assuming that because the 12F1822 is a new part with added features such as automatic context saving etc, I need to do some changes to the MIBAM code, but I really am not sure where to start.. looking to see if anyone has tried using MIBAM on newer pics?
untill then going to go brush up on my assembly knowledge some and see what trouble I can get myself into changing things...
Bookmarks