![]() | ![]() | ![]() |
| | #16 | |
| Quote:
_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. | ||
| |
| | #17 | ||
| Quote:
Quote:
| |||
| |
| | #18 |
|
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.
| |
| |
| | #19 |
|
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.
__________________ "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. | |
| |
| | #20 |
|
Your formatting is off Gaspode, can you edit it for him? Use "preview post" | |
| |
| | #21 |
|
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) | |
| |
| | #22 |
|
I use Firefox and it's pointing at the 8th bit from the right
| |
| |
| | #23 |
|
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) | |
| |
| | #24 |
|
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) | |
| |
| | #25 |
|
Beautiful now, I'm sure he will understand!
| |
| |
| | #26 |
| Code: Monospaced fonts are your friend! | |
| |
| | #27 |
|
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 | |
| |
| | #28 |
|
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.
| |
| |
| | #29 |
|
I'll have your program rewritten by this afternoon.
| |
| |
| | #30 |
|
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 | |
| |
|
| 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 |