PDA

View Full Version : How to use Analog interrupt in 16f72



kvrajasekar
- 1st September 2008, 07:35
Hi,



I am interested to connect main power supply to RA0(16f72),for that i have plan to set analog interrupt to know the main present ,Can anyone help me how to enable analog interrupt.



I thought PIE1 is used for that.Plz explain me how to use intr.



waiting for reply.



-Raja.

Jerson
- 1st September 2008, 14:21
Raja,

You're not being very clear on why you need the mains to connect to the PIC. Is it to just detect presence of mains, or is it for timing the zero crossing?

In the first case, you simply convert the mains to a low voltage DC and read it digitally or via the ADC.

In the second case, a simple half wave rectifier followed by a voltage divider will let you catch the zero crossings.

Good luck

kvrajasekar
- 2nd September 2008, 06:39
Hi jerson,

Thanks for ur response.I am designin UPS control operation using 16f72.my confusion is how to know whether main is present or not.

1.If main is present,operation continues with main power
2.if not inverter should continue the task.

here power failure indication is one i/p to PIC.so,i am thinkin to connect it to RB0/INT.so that i can start inverter.in case of power resumption,i should start the main with some delay,
i used the intr routine like,

;power failure condition
;RB0/INT vector
org 0x04
btfsc INTCON,INTF ;in case power failure i/p is 0,start main.
goto inverter_start
goto start_main

Plz give ur suggestion.

I have another doubt.I used LCD display to display the character,
i used the code like

movlw "U"
call disp
movlw "P"
call disp
movlw "S"
call disp


If i use like this will increase the memory.i want to save the memory,so instead of these,can i use DB or DT

like
dt "UPS"
call disp


-Regards,
Raja.

Jerson
- 2nd September 2008, 10:52
The first technique of providing a DC level to the PIC to indicate mains present should suffice in your case. However, I do not see the need for it to interrupt the code.

Secondly, you seem to be coding totally in assembler. So, I think this thread should be in the Off Topic section of the forum.

The technique of declaring the string in a readable fashion makes more programming sense as it is easier to spot while modifying your code later and will be more compact in flash and execution time too.

Good luck

kvrajasekar
- 2nd September 2008, 11:49
Thanks,
I am using ASM code.

but while passing the string like

dt "UPS"

needs any change in the program?
or
it is just the substitute of seperate character.plz clear me.
lcd_init

movlw 0x28 ; 4 bit, 2 Line, 5x7 font
call disp_cmd
call delay
movlw 0x10 ; display shift off
call disp_cmd
call delay
movlw 0x01 ; Clear the Display RAM
call disp_cmd
call delay ; Note, Can take up to 4.1 msecs
movlw 0x06 ; increment cursor
call disp_cmd
call delay
movlw 0x02 ; move the cursor to begining
call disp_cmd
call delay
movlw 0x0C ; display on cursor off
call disp_cmd
call delay
return

;Display command for 4 bit LCD

disp_cmd ; Send the Instruction to the LCD
movwf Temp ; Save the Temporary Value
swapf Temp, w ; Send the High Nybble
bcf LCD_RS ; RS = 0
call nibbleout
movf Temp, w ; Send the Low Nybble
bcf LCD_RS
call nibbleout
return
;------------------------------------------------------------------------------------
;sending ASCII character to LCD
disp_write
addlw '0' ; Send nbr as ASCII character ; Send the Character to the LCD
movwf Temp ; Save the Temporary Value
swapf Temp, w ; Send the High Nybble
bsf LCD_RS ; RS = 1
call nibbleout
movf Temp, w ; Send the Low Nybble
bsf LCD_RS
call nibbleout
return
;sending lower and upper nibble
nibbleout
movwf PORTB
bsf LCD_E
bcf LCD_E
nop
nop
return
movlw 'UPS' ;displayin the string on LCD
call disp_write

can i write like this?plz reply me.

-Raja.