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
 
Thread Tools Display Modes
Old 13th May 2008, 08:06 AM   (permalink)
Experienced Member
c36041254 is on a distinguished road
Question Simple PIC programming problem

I have successfuly programmed LED flashing programme with those normal codes (MOV and all that..) now, I'm trying this XOR one but, don't understand why this is not working.


Code:
list p=16f690
	#include<p16f690.inc>
	
	#define LED PORTC,0;Define pin 0 of port c as LED
	
	__CONFIG  _MCLRE_ON & _CP_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT
	ERRORLEVEL    -302

TEMP_VAR UDATA
temp     RES 1
delay1   RES 1;reserves 1 byte for delay1
delay2   RES 1;reserves 1 byte for delay2

;*******************************************************************
Main:;Main programme begains
	CODE 0x05; Start address at 0x05
Setpins:; Select output and input
	bsf STATUS,RP0 ;Switch to bank 1
	movlw b'11110';MOVe 11110 to W
	movwf TRISC    ;set pin 0 of PORT C as output
	bcf STATUS,RP0 ;Switch back to bank 0
	movlw b'00001';MOVe 00001 to W
Start:
	xorwf LED
	call Loop
	call Loop
	goto Start
Loop:
	decfsz delay1,1
	goto Loop
	decfsz delay2,1
	goto Loop
	return
	END
c36041254 is offline   Reply With Quote
Old 13th May 2008, 08:18 AM   (permalink)
Super Moderator
 
Nigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to behold
Default

How about specifing a destination for the XORWF instruction?.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline   Reply With Quote
Old 13th May 2008, 08:18 AM   (permalink)
Experienced Member
 
ericgibbs is a splendid one to beholdericgibbs is a splendid one to beholdericgibbs is a splendid one to beholdericgibbs is a splendid one to beholdericgibbs is a splendid one to beholdericgibbs is a splendid one to beholdericgibbs is a splendid one to beholdericgibbs is a splendid one to behold
Default

hi,
I cannot see that LED has been declared.?

xorwf LED

You pipped me again Nigel, I must be getting slower...

I'll opt out of this one.
__________________
Eric
"Good enough is Perfect"

PIC tutorials:
Gramo's: www.digital-diy.net/
Bill's: www.blueroomelectronics.com/
ericgibbs is offline   Reply With Quote
Old 13th May 2008, 08:29 AM   (permalink)
Experienced Member
 
Blog Entries: 1
Gayan Soyza is a glorious beacon of lightGayan Soyza is a glorious beacon of lightGayan Soyza is a glorious beacon of lightGayan Soyza is a glorious beacon of lightGayan Soyza is a glorious beacon of light
Default

Code:
Start	movlw 	b'00001'
	xorwf	PORTC,F
	call 	Loop
	call 	Loop
	goto 	Start
__________________
Gayan
Forum Supporter
Gayan Soyza is online now   Reply With Quote
Old 13th May 2008, 09:35 AM   (permalink)
Experienced Member
c36041254 is on a distinguished road
Unhappy Re:Simple PIC pro. problem

I tried what Gayan Soyza suggested but, that is not working and I am already using Nigel's tutorials they are very helpful but, I can't see any special help on XOR, please help me, I'm on this for hours, trying to blink just an LED with XOR code !, please point out where is the mistake I'm just a layman!
c36041254 is offline   Reply With Quote
Old 13th May 2008, 09:53 AM   (permalink)
Experienced Member
 
geko is just really nicegeko is just really nicegeko is just really nice
Default

At the top of your code you use the following

Code:
#define LED PORTC,0;Define pin 0 of port c as LED
but then you try to toggle the LED using this instruction in the main code

Code:
xorwf LED
which if you substitute your definition for 'LED' is

Code:
xorwf PORTC,0
The 0 here isn't the bit you want to toggle it's the destination for the result of the XOR operation. The 0 tells it to put the result in W so your code never writes anything back to PORTC.

What you want is

Code:
 
xorwf PORTC, F
__________________
Pete
picprojects.org.uk
geko is offline   Reply With Quote
Old 13th May 2008, 10:27 AM   (permalink)
Experienced Member
 
geko is just really nicegeko is just really nicegeko is just really nice
Default

Also, you need to turn off analogue mode and set the port to digital I/O. See datasheet

Code:
 
Setpins:; Select output and input
 
      bsf STATUS,RP0               ;Switch to bank 1
      movlw b'11110'                 ;MOVe 11110 to W
      movwf TRISC                   ;set pin 0 of PORT C as output
 
      bcf   STATUS, RP0           ; Switch to bank 2   
      bsf   STATUS, RP1
 
      bcf   ANSEL, ANS4           ; Set PORTC, 0 to digital mode
 
      bcf STATUS,RP0              ;Switch back to bank 0
      bcf STATUS,RP1
 
     movlw b'00001'          ;MOVe 00001 to W
Start:        
 
     xorwf PORTC,F
     call Loop
     call Loop
     goto Start
Loop:         
 
     decfsz delay1,1
     goto Loop
     decfsz delay2,1
     goto Loop
     return
__________________
Pete
picprojects.org.uk
geko is offline   Reply With Quote
Old 13th May 2008, 11:47 AM   (permalink)
Experienced Member
c36041254 is on a distinguished road
Exclamation Re:Simple PIC pro. problem

Hmm....... that works , but what I did'nt understand is that why it is:

bcf ANSEL,ANS4

and why not,:

bcf ANSEL,ANS0

After all the LED is connected at pin 0 of port c and not at pin 4

I mean the data sheet says :

Setting the ANSx bit of a corresponding pin will
cause all digital reads of that pin to return ‘0’ and also
permit analog functions of that pin to operate correctly.

Please explain as easily as possible, Thank you for your help !!
c36041254 is offline   Reply With Quote
Old 13th May 2008, 11:55 AM   (permalink)
Experienced Member
 
geko is just really nicegeko is just really nicegeko is just really nice
Default

Quote:
Originally Posted by c36041254
Hmm....... that works , but what I did'nt understand is that why it is:

bcf ANSEL,ANS4

and why not,:

bcf ANSEL,ANS0

After all the LED is connected at pin 0 of port c and not at pin 4
Read the data sheet again. The Analogue bit numbers don't correspond to the same port bit numbers; how could they since you have PortA,0 and PortC,0 and they're both analogue inputs.
__________________
Pete
picprojects.org.uk
geko is offline   Reply With Quote
Old 13th May 2008, 01:28 PM   (permalink)
Experienced Member
c36041254 is on a distinguished road
Unhappy Re:Simple PIC pro. problem

I'm sorry but I still don't get that, I know this may sound stupid to you but I'm working with .ASM since last few days only, I have checked all registers associated with port c (that is given in table format in datasheet) and I found that ANS4 is corresponds to bit 4 and bit 4 also corresponds to pin 4 of port c, I know you are trying to tell me something quite different but, if you can make it more simpler than I'll be very grateful !
c36041254 is offline   Reply With Quote
Old 13th May 2008, 02:13 PM   (permalink)
Experienced Member
 
geko is just really nicegeko is just really nicegeko is just really nice
Default

Quote:
Originally Posted by c36041254
I'm sorry but I still don't get that, I know this may sound stupid to you but I'm working with .ASM since last few days only, I have checked all registers associated with port c (that is given in table format in datasheet) and I found that ANS4 is corresponds to bit 4 and bit 4 also corresponds to pin 4 of port c, I know you are trying to tell me something quite different but, if you can make it more simpler than I'll be very grateful !
If you want a port bit to function as digital I/O you have to clear the corresponding bit in the ANSEL or ANSELH registers.

AN0 thru AN7 are set in the ANSEL register and AN8 thru AN11 in ANSELH.

If for example you want to use port RB4 as digital I/O you would clear ANS10 bit in ANSELH register.
__________________
Pete
picprojects.org.uk
geko is offline   Reply With Quote
Old 13th May 2008, 03:01 PM   (permalink)
Experienced Member
c36041254 is on a distinguished road
Red face Re:Simple PIC pro. problem

Oh! that was very easy, right before my eyes, it is also given in table 1.5, Thank you very much and sorry to bother you about this, now I think that it is out of quastion that why Microchip built it like this (AN4 fo RC0) as it is related to archtructure stuff, is'nt it ?, we just have to accept as it is.
c36041254 is offline   Reply With Quote
Old 13th May 2008, 03:13 PM   (permalink)
Experienced Member
 
Blog Entries: 4
blueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to behold
Send a message via Skype™ to blueroomelectronics
Default

To save memory they pack lots of sometimes unrelated bits into a single register.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com
blueroomelectronics is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
Any way of programming PIC 16c54 on Velleman bigal_scorpio General Electronics Chat 5 10th April 2008 11:05 AM
PIC USART-HyperTerminal problem.. asp1987 Micro Controllers 17 8th April 2008 07:00 PM
PIC programming problems rogerjef Micro Controllers 12 23rd February 2008 10:25 PM
PIC pin to MOSFET gate problem Futterama Electronic Projects Design/Ideas/Reviews 7 8th November 2007 05:30 PM
STK500 and Tiny11 programming problem. mramos1 Micro Controllers 0 8th May 2006 02:57 PM



All times are GMT. The time now is 05:57 AM.


Electronic Circuits  |  Radio Controlled
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.