This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Help with external crystal...

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.

Parents
  • "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

Reply
  • "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

Children
  • 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...

  • What does this sentence means?

    "Crystal Oscillator Mode with divide by 2 stage."

    Does this means that the crystal frequency is divided by 2?

  • I tried debugging my code... But the LCD only display "000 BPM".
    I took a sample of 5 seconds to get the pulses. I read through my code and found all of it logical (from my knowledge). Anyone can help me to find out the problem?
    Here is my timer and oscillator code:

    
    MOV OSCXCN,#062H        ; External Oscillator Control Register
    CLR A            ; Clear value of Accumulator
    DJNZ ACC,$      ; Wait for
    DJNZ ACC,$      ; at least 1ms
    
    OX_WAIT:        MOV A,OSCXCN ; Move data in OSCXCN to Accumulator
    JNB ACC.7,OX_WAIT ; Poll XTLVLD
    MOV OSCICN,#008H        ; Internal Oscillator Control Register
    
    
    MOV IE,#8CH
    MOV IP,#04H
    
    SETB TCON.2
    MOV TMOD,#10H
    MOV CKCON,#000H
    
    
    ;*************
    ;-Start Timer-
    ;*************
    START:  MOV TH1,#0C9H
            MOV TL1,#50H  ; Program timer to run for 5 seconds
            MOV R3,#00H
            SETB TR1             ; Start timer
    ;****************************
    ;-Timer 1 Overflow Interrupt-
    ;****************************
    T1_INT: CLR TF1 ; Clear overflow flag
            MOV TH1,#0C9H
            MOV TL1,#50H
            RETI
    
    ;**********************
    ;-External Interrupt 1-
    ;**********************
    EX_INT1:   INC R3       ; Increment R3
               MOV A,R3 ; Move data in R3 to Accumulator
              RETI
    

    After this, i use a routine to convert binary HEX to ASCII and display.