Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

help with programing 16f690

Status
Not open for further replies.
You can but that code is reading 5 values and changing the whole portc not just a pin
so if you don't set it to turn on the same pin for 2 2.5 3 4 it will turn it off and turn on the next it's like a meter that reads volt it's going to go higher and and when it dose it dose what is next.
Like this
Code:
list		p=16f690		; list directive to define processor
	#include	<P16F690.inc>		; processor specific variable definitions
	errorlevel -302 ; Turn off banking message
                            ; known tested (good) code

	__config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF)


	CBLOCK 		0x020
	endc
	#define _.8VOLT 0x28
	#define _1VOLT 0x33
	




	ORG			0x000		; processor reset vector
  	goto		init		; go to beginning of program


	ORG			0x004	    ; interrupt vector location

init:
     bsf       STATUS,RP0     ; select Register Page 1
     movlw     0xFF
     movwf     TRISA          ; Make PortA all input
     clrf      TRISC          ; Make PortC all output
     movlw     0x10           ; A2D Clock Fosc/8
     movwf     ADCON1
     bcf       STATUS,RP0     ; back to Register Page 0

     bcf       STATUS,RP0     ; address Register Page 2
     bsf       STATUS,RP1     
     movlw     0xFF           ; we want all Port A pins Analog
     movwf     ANSEL
     bcf       STATUS,RP0     ; address Register Page 0
     bcf       STATUS,RP1
     clrf	   ADCON0
     movlw     0x01
     movwf     ADCON0         ; configure A2D for Channel 0 
MainLoop:
     call	adcdelay		  ;delay to charge cap
     bsf       ADCON0,GO      ; start conversion
     btfss     ADCON0,GO      ; this bit will change to zero when the conversion is complete
     goto      $-1
	
    movf     ADRESH,w       ; Copy the display to the LEDs
	movwf	 PORTC
	goto      MainLoop
    movlw 	_.8VOLT
    subwf	 ADRESH, w
	BNC 	LessThan1V                ; Branch if less than 1V

	movf     ADRESH,w       ; Copy the display to the LEDs
    movlw 	_1VOLT
    subwf	 ADRESH, w
	BNC 	LessThan2V                ; Branch if Between 1V and 2V
	

    goto      MainLoop
LessThan.8V:
	bsf 	PORTC,0
	return 
LessThan1V:
	bsf		PORTC,1
	return


   
adcdelay:
	 nop					  ;1 cycle

	 return					  ;4 cycles (including call)
	
     end
 
Last edited:
You can but that code is reading 5 values and changing the whole portc not just a pin
so if you don't set it to turn on the same pin for 2 2.5 3 4 it will turn it off and turn on the next it's like a meter that reads volt it's going to go higher and and when it dose it dose what is next.
Like this
Code:
list		p=16f690		; list directive to define processor
	#include	<P16F690.inc>		; processor specific variable definitions
	errorlevel -302 ; Turn off banking message
                            ; known tested (good) code

	__config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF)


	CBLOCK 		0x020
	endc
	#define _.8VOLT 0x28
	#define _1VOLT 0x33
	




	ORG			0x000		; processor reset vector
  	goto		init		; go to beginning of program


	ORG			0x004	    ; interrupt vector location

init:
     bsf       STATUS,RP0     ; select Register Page 1
     movlw     0xFF
     movwf     TRISA          ; Make PortA all input
     clrf      TRISC          ; Make PortC all output
     movlw     0x10           ; A2D Clock Fosc/8
     movwf     ADCON1
     bcf       STATUS,RP0     ; back to Register Page 0

     bcf       STATUS,RP0     ; address Register Page 2
     bsf       STATUS,RP1     
     movlw     0xFF           ; we want all Port A pins Analog
     movwf     ANSEL
     bcf       STATUS,RP0     ; address Register Page 0
     bcf       STATUS,RP1
     clrf	   ADCON0
     movlw     0x01
     movwf     ADCON0         ; configure A2D for Channel 0 
MainLoop:
     call	adcdelay		  ;delay to charge cap
     bsf       ADCON0,GO      ; start conversion
     btfss     ADCON0,GO      ; this bit will change to zero when the conversion is complete
     goto      $-1
	
    movf     ADRESH,w       ; Copy the display to the LEDs
	movwf	 PORTC
	goto      MainLoop
    movlw 	_.8VOLT
    subwf	 ADRESH, w
	BNC 	LessThan1V                ; Branch if less than 1V

	movf     ADRESH,w       ; Copy the display to the LEDs
    movlw 	_1VOLT
    subwf	 ADRESH, w
	BNC 	LessThan2V                ; Branch if Between 1V and 2V
	

    goto      MainLoop
LessThan.8V:
	bsf 	PORTC,0
	return 
LessThan1V:
	bsf		PORTC,1
	return


   
adcdelay:
	 nop					  ;1 cycle

	 return					  ;4 cycles (including call)
	
     end

This is not doing what I need, I need the 'ON' trigger point at the higher voltage. This on voltage will be higher than the 'OFF' Voltage, so it needs to go high when it reaches 1v, then as the fan is running it will cool the system down and the input will finally reach .8v, representing a cooler temp there for the fan will turn off. Hope that makes sense:)
 
You can do what you want the way this code works is if the value is higher it skips that value till it finds one that it is less then it branches on no carry and dose what you tell it and returns.
If you want motor to come on at any thing above 1volt you check for that and if so turn motor on and then start checking for it to go low .8volts
 
Status
Not open for further replies.

Latest threads

Back
Top