;******************************************
;PIC12F675
;MPASM assembler
;MPLAB 8.10
;Programmer = Pickit2
;Application version 2.11.00
;Device File Version 1.12.00
;OS Firmware version 2.20.01
;Internal Oscillator at 4MHz
;--------------------------------------
;PIN USAGE
;AN0 = analog input;
;AN1 = analog input;
;RA2 = digital output;
;RA4 = digital output;
;RA5 = digital input;
;--------------------------------------
#include <p12f675.inc>
LIST P=PIC12F675
__config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BODEN_OFF & _CPD_OFF)
cnt0 equ 0x20
cnt1 equ 0x21
cnt2 equ 0x22
cnt3 equ 0x23
ccd0 equ 0x24
val0 equ 0x25
val1 equ 0x26
ded0 equ 0x27
ded1 equ 0x28
BANK0 macro
bcf STATUS,RP0
endm
BANK1 macro
bsf STATUS,RP0
endm
FET_ON macro
bsf GPIO,2
endm
FET_OFF macro
bcf GPIO,2
endm
ENABLE macro
bsf GPIO,4
endm
DISABLE macro
bcf GPIO,4
endm
ENABLE_ADC macro
bsf ADCON0,0
nop
endm
DISABLE_ADC macro
bcf ADCON0,0
nop
endm
ADC_CH0 macro
bcf ADCON0,3
nop ;nop to avoid RMW problem
bcf ADCON0,2
nop
endm
ADC_CH1 macro
bcf ADCON0,3
nop ;nop to avoid RMW problem
bsf ADCON0,2
nop
endm
DO_ADC macro
bsf ADCON0,1
nop
endm
org 0
goto Start
Start:
FET_OFF
DISABLE
BANK1
;Set up ANSEL register (set analog/digi ports
;..set up AD conversion clock)
movlw 0x63
movwf ANSEL
;Sort comparator reference out even though
;i dont want to use the comparator
movlw 0x00
movwf VRCON
movlw 0x2B
movwf TRISIO
BANK0
;Disable interrupts as i don't want to use them
bcf INTCON,GIE
bcf PIR1,ADIF
;Sort comparator out even though i dont
;want to use it.
movlw 0x06
movwf CMCON
;The comparator ref must still be enabled
;even though i dont want to use the comparator
BANK1
bsf VRCON,VREN ;Enable comparator ref
BANK0
;Set up ADCON0 = Ljust; Vdd = ref; xx; CHS = 00; GODONE; Disable
movlw 0x00
movwf ADCON0
ENABLE_ADC
FET_OFF
DISABLE
;VVVVVVVVVVVVVVVVVVVVV
;* MAIN PROGRAM LOOP *
loop:
;...........................
;Do ADC on channel 0
bcf PIR1,ADIF
nop
DISABLE_ADC
ADC_CH0 ;Change ADC channel
ENABLE_ADC
call ADC_channel_changeover_delay
D0_ADC
egg:
btfsc ADCON0,1
goto egg
;............................
movf ADRESH,0
movwf val0
movlw 0x7F
subwf val0,0
btfsc STATUS,C
FET_OFF
movlw 0x7F
subwf val0,0
btfss STATUS,C
FET_ON
;............................
;............................
;----------------------------
;Do ADC on channel 1
bcf PIR1,ADIF
nop
DISABLE_ADC
ADC_CH1 ;Change ADC channel
ENABLE_ADC
call ADC_channel_changeover_delay
DO_ADC
dog:
btfsc ADCON0,1
goto dog
;............................
movf ADRESH,0
movwf val1
movlw 0x7F
subwf val1,0
btfsc STATUS,C
DISABLE
movlw 0x7F
subwf val0,0
btfss STATUS,C
ENABLE
;----------------------------
goto loop
;* END OF MAIN PROGRAM LOOP *
;^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ADC_channel_changeover_delay:
movlw 0x0F
movwf ccd0
fff:
decfsz ccd0,1
goto fff
retlw 0x00
end
;PIC12F675
;MPASM assembler
;MPLAB 8.10
;Programmer = Pickit2
;Application version 2.11.00
;Device File Version 1.12.00
;OS Firmware version 2.20.01
;Internal Oscillator at 4MHz
;--------------------------------------
;PIN USAGE
;AN0 = analog input;
;AN1 = analog input;
;RA2 = digital output;
;RA4 = digital output;
;RA5 = digital input;
;--------------------------------------
#include <p12f675.inc>
LIST P=PIC12F675
__config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BODEN_OFF & _CPD_OFF)
cnt0 equ 0x20
cnt1 equ 0x21
cnt2 equ 0x22
cnt3 equ 0x23
ccd0 equ 0x24
val0 equ 0x25
val1 equ 0x26
ded0 equ 0x27
ded1 equ 0x28
; *** DECLARE MACRO'S ***
BANK0 macro
bcf STATUS,RP0
endm
BANK1 macro
bsf STATUS,RP0
endm
FET_ON macro
bsf GPIO,2
endm
FET_OFF macro
bcf GPIO,2
endm
ENABLE macro
bsf GPIO,4
endm
DISABLE macro
bcf GPIO,4
endm
ENABLE_ADC macro
bsf ADCON0,ADON
nop
endm
DISABLE_ADC macro
bcf ADCON0,ADON
nop
endm
ADC_CH0 macro
bcf ADCON0,CHS1
nop ;nop to avoid RMW problem
bcf ADCON0,CHS0
nop
endm
ADC_CH1 macro
bcf ADCON0, CHS1
nop ;nop to avoid RMW problem
bsf ADCON0, CHS0
nop
endm
DO_ADC macro
bsf ADCON0,1
nop
endm
; *** MACRO'S NOW DECLARED ***
org 0
goto Start
Start:
BANK1
;Set up ANSEL register (set analog/digi ports
;..set up AD conversion clock)
movlw 0x63
movwf ANSEL
movlw 0x2B
movwf TRISIO
BANK0
;Disable interrupts as i don't want to use them
bcf INTCON,GIE
bcf PIR1,ADIF
;turn comparator off
movlw 0x07
movwf CMCON
BANK1
bcf VRCON,VREN ;disable comparator ref
BANK0
;Set up ADCON0 = Ljust; Vdd = ref; xx; CHS = 00; GODONE; Disable
movlw 0x00
movwf ADCON0
nop
ENABLE_ADC
FET_OFF
nop
DISABLE
;VVVVVVVVVVVVVVVVVVVVV
;* MAIN PROGRAM LOOP *
loop:
;...........................
;Do ADC on channel 0
bcf PIR1,ADIF
nop
DISABLE_ADC
ADC_CH0 ;Change ADC channel
ENABLE_ADC
call ADC_channel_changeover_delay
D0_ADC
egg:
btfsc ADCON0,1
goto egg
;............................
movf ADRESH,0
movwf val0
movlw 0x7F
subwf val0,0
btfsc STATUS,C
FET_OFF
movlw 0x7F
subwf val0,0
btfss STATUS,C
FET_ON
;............................
;............................
;----------------------------
;Do ADC on channel 1
bcf PIR1,ADIF
nop
DISABLE_ADC
ADC_CH1 ;Change ADC channel
ENABLE_ADC
call ADC_channel_changeover_delay
DO_ADC
dog:
btfsc ADCON0,1
goto dog
;............................
movf ADRESH,0
movwf val1
movlw 0x7F
subwf val1,0
btfsc STATUS,C
DISABLE
movlw 0x7F
subwf val1,0
btfss STATUS,C
ENABLE
;----------------------------
goto loop
;* END OF MAIN PROGRAM LOOP *
;^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ADC_channel_changeover_delay:
movlw 0x0F
movwf ccd0
fff:
decfsz ccd0,1
goto fff
retlw 0x00
delay:
movlw 0xFF
movwf cnt1
mog:
movlw 0xFF
movwf cnt1
hog:
decfsz cnt1,1
goto hog
decfsz cnt0,1
goto mog
retlw 0x00
end
[code*]
sasuke_ninchan said:Hi all
I new member in this forum. i from malaysia. i new in pic12f675. i already have PICSTART plus, PIC12F675 & MPLAB IDE v8.3 software. I want to get knowledge from this furom. Hopefully i get it. So, now i searching simple assembly code for this PIC. Can u give me simple code. as example is LED blinking.
thanks
eem2am said:Hello,
I am writing in MPASM for PIC12F675.
My code builds fine but does not work properly.
#include <htc.h>
// hardware configuration
#define Vin_a GPIO0 //analyg in on GPio0;
#define CSPin GPIO1 //current sense pin on GPIO1;
#define OUTPUT GPIO5 //led out on gpio5;
// end hardware configuration
#define GETBIT(var,bit) (((var)>>(bit))&1) /* read bit from var */
#define SETBIT(var,bit) ((var)|=(1<<(bit))) /* set bit from var to 1 */
#define CLRBIT(var,bit) ((var)&=(~(1<<(bit)))) /* clear bit from var (set it to 0) */
#define Vcs_th ((long) 125*1023/5000) //input voltage threshold (125mv) to turn on the LED. from 0-1023 (10bit adc)
#define wait2 NOP();NOP()
#define wait4 wait2;wait2
#define wait8 wait4;wait4
#define wait16 wait8;wait8
#define wait32 wait16;wait16
#define wait64 wait32;wait32
#define wait128 wait64;wait64
#define wait256 wait128;wait128
#define adc_bits 7 //how many bits in pwm stepping
#define PWMLength (1<<adc_bits) //total length of pwm, should be consistent with sampling bits - 10 here
#define CSRemedy OUTPUT=OFF
#define ON 0 //output high for ON
#define OFF 1 //output low for OFF
#define Tosc8 0b0010000 //ADC at 1/8th Tosc
#define Tosc16 0b1010000 //ADC at 1/16th Tosc
#define SEL_AN0 CHS1=0; CHS0=0 //select AN0 for ADC
#define SEL_AN1 CHS1=0; CHS0=1 //select AN1 for ADC
int ADC(void) { //adc the currently selected channel
GODONE=1; //start the adc process on
while (GODONE)
; //wait for adc to complete
return (ADRESH<<8)+(ADRESL);
}
__CONFIG(MCLRDIS & INTIO & WDTDIS & BORDIS);
void
main(void)
{
int Vin_d; //adc result for Vin_a
int Vcs_d; //adc results for Current Sensor
int i=0; //where we are in length?
//OSCCAL=_READ_OSCCAL_VALUE();
CMCON=7; //turn off comparators;
TRISIO=0b11; //input on GPIO0 and GPIO1, all others digital output;
//set up ANSEL register
ANSEL=Tosc8; //Adc speed setting
ANS0=1; //GPIO0 is analog input;
ANS1=1; //GPIO1 is analog input;
//set up ADCON register
ADFM=1; //adc results right adjusted
VCFG=0; //use Vdd as reference voltage
ADON=1; //starts ADC
OUTPUT=OFF; //turn output off;
while (1){
//TODO Auto-generated main function
SEL_AN1; //select AN1 / GPIO1
Vcs_d=ADC(); //Vcs stores the results;
wait256; //wait for the Chold capacitor to charge-up
SEL_AN0; //select GPIO0;
Vin_d=ADC()>>(10-adc_bits); //adc the current channel
OUTPUT=ON; for (i=0; i<Vin_d; i++);
OUTPUT=OFF; for (i=Vin_d; i<PWMLength; i++);
// wait8; //wait to charge up Chold
}
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?