We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi guys. I changed my board to C8051F226 already and i'm using a 32.768kHz external crystal. I have read the datasheet for the oscillator. But i do not understand this sentence, can someone please explain it to me?
"Crystal Oscillator Mode with divide by 2 stage."
The datasheet also recommend me to do the following:
1.Enable the external oscillator 2.Wait 1 ms 3.Poll for XTLVLD '0' ==> '1' 4.Switch to the external oscillator
I have done the 1st 2 steps, but i can't seem to poll for XTLVLD. When i compile, it says undefined symbol.
It is telling you that "OSCXCN" is not a valid Byte Base for a Bit Address. Are you sure that "OSCXCN" is bit-addressable?
You (the OP) need to study "the bible", in particular pay attention to the little note at the bottom of fig2 in ch3
Erik
here are the links to "the bible" Chapter 1 - 80C51 Family Architecture: www.nxp.com/.../80C51_FAM_ARCH_1.pdf
Chapter 2 - 80C51 Family Programmer’s Guide and Instruction Set: www.nxp.com/.../80C51_FAM_PROG_GUIDE_1.pdf
Chapter 3 - 80C51 Family Hardware Description: www.nxp.com/.../80C51_FAM_HARDWARE_1.pdf
From what i read in the "bible", it is not bit addessable. Only the most left hand column of the SFR memory map are bit addressable. Am i right? And from the datasheet i found out that the address for the byte is at B1.
Does this means that bit 1 of OSCXCN is located at b1? and bit 7 of OSCXCN is located at b7?
MOV R1,OSCXCN WAIT1:CJNE R1,#80H,WAIT1
Isit advisable to use the above code?
I can run using the above code. But whenever i run, it will hang at the 1st line when it runs to the oscillator config routine.
This is my oscillator routine.
MOV OSCICN,#08H ; Disable internal oscillator & enable external oscillator ACALL DELAY MOV R1,OSCXCN WAIT1:CJNE R1,#80H,WAIT1 ; poll to see whether crystal is ready MOV OSCXCN,#32H ; config external crystal
Does it have something to do with my crystal or my programming?
Don't you think that you have to continuously read the value from OSCICN in you wait loop?
Why do i have to continously read value from OSCICN in my "wait" loop? OSCICN does not have any bits for me to poll. All the bits in OSCICN have been configured.
your wait-loop is going to loop untill OSCICN equals exactly 0x80. you want to mask the other bits and then test for bit 7. You could do a 'bitwise AND' of 0x80 and OSCICN, if the value is not zero then bit 7 is set.
OSCXCN you mean? Can you explain it in simpler terms? I can't really get you.
Since OSCXCN is not bit-addressable you need to use a different method of testing bit7. You should learn about bitwise operations; en.wikipedia.org/.../Bitwise_operation
MOV R1, OSCXCN ; Copies the current value from OSCXCN to R1 WAIT1: CJNE R1, #80H, WAIT1 ; Continually checks R1
If the value in OSCXCN changes, how will that affect R1 in your loop?
"From what i read in the "bible", it is not bit addessable. Only the most left hand column of the SFR memory map are bit addressable. Am i right?"
Yes.
"And from the datasheet i found out that the address for the byte is at B1."
So it's not bit-addressable, is it? (Usually datasheets explicitly note which SFRs are bit-addressable).
"Does this means that bit 1 of OSCXCN is located at b1? and bit 7 of OSCXCN is located at b7?"
No - it's not bit-addressable, so the individual bits do not have their own distinct address. You cam only address the byte as a whole - and the address for that byte is B1
I see. In the previous code, when the value in OSCXCN changes, R1 will not change because the loop does not go back to copying the new value of OSCXCN. Therefore, the program will forever hang there.
So can i use this code?
MOV OSCXCN,#062H ;External Oscillator Control Register CLR A ; osc DJNZ ACC,$ ; wait for DJNZ ACC,$ ; at least 1ms OX_WAIT: MOV A,OSCXCN JNB ACC.7,OX_WAIT ;poll XTLVLD MOV OSCICN,#008H ;Internal Oscillator Control Register
Just sidetracking abit. How do i make 2 inputs from 2 sensor go into 1 ADC and by comparing the signals to determine the signals to see which signal is better before outputting the better signal in a LCD?
"Just sidetracking a bit."
That's not just "a bit" that's a totally different and unrelated question! It's also nothing to do with Keil tools so, strictly, it's off-topic - it's actually an analogue electronic design question. You should go to the ADC manufacturers' websites for stuff like this - they have tons of stuff on it! Try TI, National Semiconductor, Analog Devices, Linear Technology, Maxim, et al...
"How do i make 2 inputs from 2 sensor go into 1 ADC"
You need a Multiplexer; there are plenty of ADCs available with these built-in - including some integrated with 8051 controllers. Again, look on the ADC manufacturers' websites.
"by comparing the signals to determine ... which signal is better"
Before you can do that, you need to define exactly what constitutes "better" for your application.
"Better" on its own like that is totally meaningless!
I see... Thanks for the info. So the code above can be used?
So the code above can be used?
Have you tested? Wouldn't a very simple test answer your question?
I tried it. and it works fine... thanks...