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.

Internal oscillator and digital input

Status
Not open for further replies.

trennonix

New Member
Hello,

I'm trying to make 2 pics (12F675) communicate together, for that, i'm using the internal oscillator

Is the internal oscillator imprecise?
Because when i run my program, sometimes it works, then a couple of hours later, i run the same exact program on the same exact untouched chips, and it crashes :confused::confused:

Now, in order to make the switch to an external oscillator (crystal) i need to rearrange my pinouts so that i have room for my crystal. In doing so, i need to take a digital input from an analogue pin, pin0.

I'm programming in assembly and i don't know anything about ADC, plus, all i need is a simple digital input and i can't figure out how to do just that.

Thanks alot.
 
The internal oscillator is accurate to 1%. This should be more that accurate enough for simple serial communication. If your code is crashing then it is probably a timing issue you haven't accounted for.

To ensure the pins are digital, you need to write zero to ANSEL.

Mike.
 
if it works for rs232 9600, then it's good enough for me
i'm running at meer 23 bits per sec :p and i'm having trouble :(

but my code works fine in a simulator,

this is the code for receiving one bit
everything else should be pretty simple, it's unlikely that i made a mistake in transmission or the reception of all bits

so can you guys plz take a look at this chunk of code:

receivebit:
call delay100Us
movlw d'8'
movwf ct8 ;sets the counter to 8 in order to get 8 cycles
movlw 0h
movwf ct7;we reset reader which is ct7 (for the addef inst)
movlw 1; increment by 1
label4
btfsc portb,5 ;reads the pin
addwf ct7,1 ;if the pin is on, we add 1 to ct7, if not, zero
call delay100Us ;delay 100us
decfsz ct8,1 ;cycles 10 times to reach period of 1ms
goto label4 ;at end of cycle this is jumped
movlw d'4' ;decrement ct7 by 4
subwf ct7 ;decrements ct7 by 4
movlw d'255' ;if zero flag is off, set to positive
btfss status,0 ;tests carry flag
movlw 0h ;if carry is on, it stays on, else, it's set to null
;BIT READ IS STORED IN ct1
movwf ct1
bcf status,0
bcf status,1
call delay100Us
return ;DONE WORKING OK


NB:

result is outputted to ct1 FF->bit received and 0x00 null

portb refers to GPI0

delay100us is not actually 100us, it's the tenth of one bit's lenght

it basically takes 8 readings during one bit lenght, and if more then four readings giveout a positive reading then a high bit is received


one more thing:
i can't seem to grasp the difference between bit 0 and 1 of status and how do they work??
 
Your code is badly formatted and difficult to read (you should post it using the 'code' tags), but check my tutorials which show how to do software 9600 baud.
 
One word of advice, use the labels in the include file, don't use numbers for defined flags, use the provided labels - check my tutorials to see what I mean.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top