MCUmall EPROM BIOS Chip Burner Forum
MCUmall EPROM BIOS Chip Burner Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 MCUmall Forums
 Novice Place
 Help to program PIC16F88
 Forum Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

Kai-Itza

1 Posts

Posted - 08/03/2010 :  08:13:07  Show Profile
Hey guys :)

I'm in a bit of a muddle with a little home project of mine and am wondering if any of you want to help.

I'm building a very simple light sensing circuit using a 1M ohm LDR (with the 1M value being the max value when in the dark), as it's getting dark the program (written in Assembler) will monitor and test the incoming ADC values until it reaches ~60% of the LDR's resistance value through the voltage that it carries, once it reaches this threshold the program would then activate a simple LED to symbolise this. Easy right? Yeah, that's what I thought until I found out that I can't get it to work :(.

This is but the first stage of a much larger project, of which I want to build up in 'building blocks', this project would eventually grow to that which looks after plantlife within my conservatory so I don't have to.

I'm relatively new to programming in general and I thought that Assembler was a good place to start, I know all the basics as I've been learning this through the Version 3 PICmicroŽ microcontroller development board from Matrix Multimedia, it's a little old I know being as it is a evaluation board that was released way back in 2003 and it still has usage in it yet. So I'll be developing this project off of this for the time being.

I'm using the PIC:16F88 for this project.

And the following is the Program that I've been working on for the last 2 weeks:

;PROGRAMMING OPTIONS************************************************
;
; When programming the PIC 16f88 using the Assembler (ASM:IDE), the following options are selected:
;
; Oscillator selection; EXTRC as clock-out
;Watchdog timer - disabled
; Power up timer - disabled
; Pin function select; MCLR
; Brown-out protection - enabled
; Code Proection - diabled
;Low Voltage program - enabled
; data EE read protect - disabled
;Flash program write enable: Write protect - disabled
;Background debug - disabled
;CCP1 Mux pin; RB0
;code proect - disabled
;fail-safe clock monitor - enabled
;internal/eternal switch over mode - enabled
;
;I/O ALLOCATION*****************************************************
;
;INPUTS...........................................................
;
;Analogue sensors (input)	AN4-AN6(VDD = 5.0V)	; There is only going to be one temperature sensor to be used through one of these pins, the reason why three have been selected is for other sensors to be added after the temperature sensor has been tried and tested successfully
;Digital I/O 		RA0-RA3 		
;
;OUPUTS...........................................................
;
; LED
;
;PORT DATA DIRECTION CODES REQUIRED...............................;
;
;
;ADC SETUP********************************************************
;
;ANSEL	bit	7	0= unimplimated
;	bits	6543	1= analog input
;	bits 	210	0= digital I/O
;
;ANSEL = 01111000	
;
;ADCON1	bit	7	1= right justify result in ADESH/scriptDRESL
;	bit	6	0= disabled (not needed)
;	bits	54	10== VREF-VSS
;	bits	3210	0= unimplemented
;
;ADCON1 = 1010000
;
;ADCON0 	bits	76	0= A/D clock = f/8
;	bits 	543	channel select (AN0-AN7)
;	bit	2	GO=1/DONE=0
;	bit	0	A/D Module enable = 1
;
;ADCON0 = 01111001
;
;	Create  list file and select processor :
	list p = 16f88
;
#DEFINE	PAGE0 BCF STATUS,5
#DEFINE	PAGE1 BSF STATUS,5
;
;	Include file containing register labels:
	Include "p16f88.inc"
;
STATUS	EQU H'03'	; STATUS register
count 	EQU 020		; assign General Purpose Register, Bank 0 for counter 
z	EQU 2		;Zero flag
;
;set origin at address 000
org	0x000

				
	ORG	0		; Reset vector
	GOTO	5		; Goto start of program
	ORG	4		; Interrupt vector
	GOTO	5		; Goto start of program
	ORG	5		; Start of program memory

	; set up code for 16F88 ports
	BSF	3,5	;switch to page 1
	CLRF	H'9b'	;clear ansel file - set ports to digital io
	BCF 	3,5	;switch to page 0
;
;SETUP STATUS REGISTER............................................
;

;
;SETUP ADC........................................................
;
	banksel	ANSEL		;select register bank
	movlw	b'01111000'	
	movwf	ANSEL		;write A/D control word
;
	banksel	ADCON1		;select register bank
	movlw	b'10100000'	
	movwf	ADCON1		;write A/D control word
;
	banksel	ADCON0		;select register bank
	movlw	b'01111001'
	movwf	ADCON0		;write A/D control word
;
;SUBROUTINE TO WAIT ABOUT 0.8MS..................................
;
delay	movlw	256		;load time delay of 256x3=768
	movwf	count		;load counter	down	decfsz	count		;decrement and test counter
	goto 	count
;
;SUBROUTINE TO GET ANALOGU INPUT - 20US SETTLING TIME.............
;
A2D	movlw	007		;time delay of 7x3=21us
	movwf	count		;load counter
again	decfsz	count		;decrement until zero
	goto 	again		;decrement until zero
;
;GET ANALOGUE INPUT..............................................
;
	movlw	b'01000001'
	movwf	ADCON0
adc	bsf	ADCON0, GO	;start a2d conversion
wait	btfsc	ADCON0, GO	;wait for conversion to complete
	goto 	wait
	movf	ADRESL, h'08'	;place in register location for testing
	movf	ADRESH,	h'09'	;place in register loaction for testing
;
	movlw	H'66'		;place the total of 614-bits
	movwf	h'35'		;in two empty locations of memory bank 0
	movlw	H'02'		;these are to test the thermistor component
	movwf	H'36'		;to see if it is >60% of it's original value
;	
	movf	H'35', w		
	subwf	H'08', H'08'	;subtract loaded ADC value from 102-bytes and place into memory
	movf	H'36', w
	subwf	H'09', H'09'	;subtract loaded ADC value from 2-bytes and palce into memory
;
	btfsc	h'08', z	;and test ADRESL...
	goto 	part2
	movlw	H'0F'		;...if the thermistor is >60% of it's original value, place the value 0F...
	movwf	H'4B'		;...into an empty register
;
part2	btfsc	H'09', z	;and then test ADRESH...
	goto	adc
	movlw	H'0F'		;...if the thermistor is >60% of it's original value, place the value 0F...
	movwf	H'4A'		;...into an empty register
;
;TEST TO SEE IF BOTH ADRESL AND ADRESH ARE BOTH POSITIVE.................
;
	movf	H'4A', w	;load the value of ADRESH into the working register
	ADDWF	H'4B', H'4A'	;add both ADRESH's and ADRESL's positive 'flags' (the values of 0F for both results), which would make the value of H'1E'
	btfss	H'4A', H'1E'	;...and test to see if this result is positive
	goto	adc
	goto	ledop		;if it is; turn on LED RB0
;
;
;
;LED OUTPUT IF THERMISTOR READS 61% OF ITS MAXIMUM VALUE..........
;
ledop 	CLRF	6		; set all Port B pins to logic 0 
 	BSF	3,5		; instruct program that a Page 1   
		 	 	; command comes next 
 	CLRF	6		; set all Port B pins as outputs 
 	BCF	3,5		; instruct program that a Page 0   
		 	 	; command comes next 
 	BSF	6,0		; set Port B pin 0 to logic 
	goto	adc		;keep testing and provide outputs as per programme parameters

	end


I've connected this up like this, the board itself is connected to the mains supply using an adapter set to 13.5v. The ADC inputs uses a +Vref of 2.55v connected into pin 2(Vref) and from that, this is then connected to the LDR which is connected to the ADC input pin 17 (AN0). The LED is already part of the Eval. Board itself.

References to the relevant datasheets can be found in the following:

[url=h**p://ww1.microchip.com/downloads/en/devicedoc/30487c.pdf]PIC:16F88[/url]
[url=h**p://www.matrixmultimedia.com/datasheets/HP488-30-3.pdf]Version 3 PICmicroŽ microcontroller development board[/url]

And, I'm using the ASM:IDE v1 debugger for assembling/debugging/building it onto the PIC:16F88

If there's anything that I missed let me know and I reply as best as I'll can, as I don't really know what's wrong with it for as far as I know, the programming and connections are correct. Can someone help me on this as I'm getting a bit confused over this :(.

Thanks for your time.


-Kai-Itza-
  Previous Topic Topic Next Topic  
 Forum Locked
 Printer Friendly
Jump To:
MCUmall EPROM BIOS Chip Burner Forum © Copyright 2003 - 2009 Mcumall Electronics Inc. Go To Top Of Page
Generated in 0.06 sec. Snitz Forums 2000