Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 19th September 2009, 07:14 AM   #16
Default

Quote:
Originally Posted by lebohangmaphothoane View Post
I am not sure on the configuration, should i disable watchdog timer or not? and could u explain what im doing when i write this instruction __config _CP_OFF & _WDT_OFF & _RC_OSC may i did not understand it very well from where i read it and could u show me how to set or declare the oscillator for PIC16F877A, i think i have to use it, like i told u i am not sure which oscillator i must use
__config_CP_OFF - No code protection, this is correct
_WDT_OFF - No watchdog timer, this is also OK
_RC_OSC - Use external R/C oscillator (R/C=resistor & capacitor) - unfortunately nowhere in the thread does it give your hardware configuration so I don't know if this is correct or not. If you have an external crystal it would either be XT or HS (depending on your crystals frequency)
__________________
"A lie gets halfway around the world before the truth has a chance to get its pants on" - Sir Winston Churchill (1874 - 1965)

Last edited by gaspode42; 19th September 2009 at 07:14 AM.
gaspode42 is offline  
Old 19th September 2009, 04:05 PM   #17
Default

Quote:
include "C:\Program Files\Microchip\MPASM Suite\p16f5x.inc"
Should be :

Quote:
include "pic16f877a.inc"
To make the assembler happy
__________________
Mike
My website: www.ElectroBird.net
birdman0_o is online now  
Old 21st September 2009, 04:37 AM   #18
Default

output voltage of the light sensor i am going to use ranges from 0v to 5v and when converting this number to digital using a ten bit number. 5v represent 1023 and 2.5v represent 512 and 0v represent 0, so follows the other numbers. i want the code to work like this, if output voltage from the sensor ranges from 2.5v to 0v then i should use ADC to get a number from 512 to 0 and then turn the LED on. else if it ranges from 5v to 2.5v then i sholud use ADC to get a number from 1023 to 512 and then turn off the LED. I know how to convert analog to digital but i do not know how to use that digital number to turn on or off the LED. if it was an eight bit number that would be easy for me because all the bits are stored in the same register. so for a ten bit number, eight bit are stored in one register and the other two are stored in a different register, therefore i do not know how to turn on or off the LED using ten bit number, please help me with the instructions.
lebohangmaphothoane is offline  
Old 21st September 2009, 08:07 AM   #19
Default

Hi

This had already been explained to you by Birdman0_o in this thread. To test if you number is > 512 you need to test the 10th digit. This you will fin in the 2nd place of ADRESH as follows:



You can test with either BTFSC or BTFSS bepending on if you are testing for it being high or low.
Attached Thumbnails
Light control system for smart home-bit.png  
__________________
"A lie gets halfway around the world before the truth has a chance to get its pants on" - Sir Winston Churchill (1874 - 1965)

Last edited by gaspode42; 21st September 2009 at 01:48 PM.
gaspode42 is offline  
Old 21st September 2009, 12:58 PM   #20
Default

Your formatting is off Gaspode, can you edit it for him?
Use "preview post"
__________________
Mike
My website: www.ElectroBird.net
birdman0_o is online now  
Old 21st September 2009, 01:18 PM   #21
Default

Mike

On my screen the post looks fine - how far out is it?

R
__________________
"A lie gets halfway around the world before the truth has a chance to get its pants on" - Sir Winston Churchill (1874 - 1965)
gaspode42 is offline  
Old 21st September 2009, 01:20 PM   #22
Default

I use Firefox and it's pointing at the 8th bit from the right
__________________
Mike
My website: www.ElectroBird.net
birdman0_o is online now  
Old 21st September 2009, 01:25 PM   #23
Default

Hum...I also use firefox and it's spot on, I will do a PDF instead
__________________
"A lie gets halfway around the world before the truth has a chance to get its pants on" - Sir Winston Churchill (1874 - 1965)
gaspode42 is offline  
Old 21st September 2009, 01:49 PM   #24
Default

Mike,

This should be OK now, thanks
__________________
"A lie gets halfway around the world before the truth has a chance to get its pants on" - Sir Winston Churchill (1874 - 1965)
gaspode42 is offline  
Old 21st September 2009, 03:36 PM   #25
Default

Beautiful now, I'm sure he will understand!
__________________
Mike
My website: www.ElectroBird.net
birdman0_o is online now  
Old 21st September 2009, 05:30 PM   #26
Default

Code:
Monospaced fonts are your friend!
Mr RB is offline  
Old 23rd September 2009, 02:38 AM   #27
Default

Thanks guys, hear is the code i have corrected. it does not have errors, i tested it on MPLAB IDE v8.5. But it has warnings and masseges,i tried to get rid of those warnings but i could not. can u guys show me why there is those warnings and how should i get rid off them.



;PROGRAM FUNCTION:light control for smart home

list P=16F877a

include "P16F877a.inc"
__config 0x3D18
;Declarations:


NumH equ 20h
NumL equ 21h
org 0x0000


; Initializing porta
BCF STATUS, RP0 ;
BCF STATUS, RP1 ; Bank0
CLRF PORTA ; Initialize PORTA by
; clearing output
; data latches
BSF STATUS, RP0 ; Select Bank 1
MOVLW 0x06 ; Configure all pinss
MOVWF ADCON1 ; as digital inputs
MOVLW 0xCF ; Value used to
; initialize data
; direction
MOVWF TRISA ; Set RA<3:0> as inputs
; RA<5:4> as outputs
; TRISA<7:6>are always
; read as '0'.


return


;Program Start:

Start
call Init ;sets the values of ADCON0 and ADCON1
;initialize porta




Main
; Read_ADC
bsf ADCON0, GO_DONE ;initiate conversion
btfsc ADCON0, GO_DONE
goto $-1 ;wait for ADC to finish

movf ADRESH,W
andlw 0x03
movwf NumH
BANKSEL ADRESL
movf ADRESL,W
BANKSEL ADRESH
movwf NumL ;return result in NumL and NumH


btfss NumH,1
goto led_on
bcf PORTA,4 ; turn 0ff the LED
goto Main
led_on
bsf PORTA,4 ;turn on the LED

goto Main


;Subroutines:
; initialize ADC
Init movlw b'10000001';
movwf ADCON0 ;
BANKSEL ADCON1
movlw b'10000101'
movwf ADCON1
BANKSEL ADCON0

return


END
lebohangmaphothoane is offline  
Old 23rd September 2009, 02:44 AM   #28
Default

birdman0 o i still remember how you said i should paste the code, i tried to paste it like that but i could see how to do it. iam sorry for that.
lebohangmaphothoane is offline  
Old 23rd September 2009, 01:25 PM   #29
Default

I'll have your program rewritten by this afternoon.
__________________
Mike
My website: www.ElectroBird.net
birdman0_o is online now  
Old 23rd September 2009, 01:39 PM   #30
Default

Nvm, did it fast, and it compiled!


Code:
;Author : Leprechaun
;Date: September 23rd 2009
;PROGRAM FUNCTION:light control for smart home

	list P=16F877a
	include "P16F877a.inc"
	__config 0x3D18

;***Declarations***
	CBLOCK 20h
	NumH
	NumL
	ENDC
;***

	ORG 0x000
	GOTO Init
	ORG 0x004

Init
							
	CLRF PORTA 			; Initialize PORTA by
	BSF STATUS, RP0 	; Select Bank 1
	MOVLW 0x06 			; Configure all pins
	MOVWF ADCON1 		; as digital inputs
	MOVLW 0xCF 			; Value used to initialize data direction
	MOVWF TRISA 		; Set RA<3:0> as inputs RA<5:4> as outputs TRISA<7:6>are always read as '0'.
	MOVLW b'10000101'	;
	MOVWF ADCON1		;

	BCF   STATUS,RP0	;
	MOVLW b'10000001'	;
	MOVWF ADCON0 		;

;Program Start:

Main
						; Read_ADC
	BSF ADCON0, GO_DONE ;initiate conversion
	BTFSC ADCON0, GO_DONE
	GOTO $-1 			;wait for ADC to finish

	MOVF ADRESH,W
	MOVWF NumH
	BSF STATUS,RP0
	MOVF ADRESL,W
	MOVWF NumL 			;return result in NumL and NumH
	BCF STATUS,RP0

	BTFSS NumH,1
	GOTO led_on
	BCF PORTA,4 		; turn 0ff the LED
	GOTO Main
led_on
	BSF PORTA,4			;turn on the LED

	GOTO Main

	END
__________________
Mike
My website: www.ElectroBird.net
birdman0_o is online now  
Reply

Tags
control, home, light, smart, system

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
Guys this is my home made 2.1 Home Theater System pasanlaksiri Electronic Projects Design/Ideas/Reviews 40 11th November 2009 05:07 AM
Traffic light control system with timer display hocklin12 Electronic Projects Design/Ideas/Reviews 6 7th May 2009 09:10 PM
smart traffic light: HELP! Crystal86 Electronic Projects Design/Ideas/Reviews 3 22nd January 2009 04:17 PM
smart home using blue tooth jayanthi Electronic Projects Design/Ideas/Reviews 4 4th September 2008 04:29 PM
traffic light control system samcheetah Electronic Projects Design/Ideas/Reviews 3 3rd May 2004 07:30 PM



All times are GMT. The time now is 08:59 PM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker