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

store data in C lang..

Hi everyone,

I've some problem storing the data in register on C lang. My SBUF was stored with some data and i want to view what data was inside. I want to store my SBUF value into R0 but i not sure how to write the code in C lang.

I know that in asembly lang, it was MOV R0, #01H<<<<<example

Can anyone help me on this? Thanks alot

Parents
  • Sorry, i will look clearly on the preview before i post out.
    Here you go.

    #include<f200.h>
    #include <stdio.h>
    #define RS P15
    #define RW P16
    #define E P17

    sfr16 RCAP2 = 0xCA; // Timer2 capture/reload
    sfr16 TMR2 = 0xCC; // Timer2

    #define BAUDRATE 9600 // Baud rate of UART in bps
    #define SYSCLK 110592000L // SYSCLK in Hz

    void PORT_Init (void);
    void UART0_Init (void);
    unsigned char RX_Ready =0;

    void delay(unsigned long duration)
    {
            while((duration--)!=0);
    }
    


    void setSystem();

    void strobe(unsigned char lcd_data)
    {
            E=1;
            delay(150);
            E=0;
            delay(150);
    }
    

    void LCD_init()
    {
      unsigned char x;
    
      for (x=0;x<3;x++)
       {
           P3=0x30;
           RS=0;
           RW=0;
           strobe();
           delay(1500);
        }
           P3=0x38;
           strobe();
           P3=0x0c;
           strobe();
           P3=0x01;
           strobe();
           P3=0x02;
           strobe();
    }
    


    //----- LCD Character Print routine --------

    void LCD_Print(unsigned char x)
    {
            P3 = x;
            RS = 1;
            RW=0;
            E=1;
            strobe(0x01);
    }
    


    //----- LCD Command ----------

    void lcdCommand(unsigned char x){
            P3 = x;
            RS = 0;
            RW=0;
            strobe(0x01);
    }
    
    void PORT_Init (void)
    {
       PRT0MX = 0x01;                      // Enable UART0
       PRT2MX = 0x80;                      // Enable global weak pull-up
       PRT0CF = 0x02;                      // RX is push-pull
    }
    

    void UART0_Init (void)
    {
       CKCON = 0x20;                       // Timer2 uses the system clock
       T2CON = 0x34;                       // Timer2 used for TX and RX, enabled
       RCAP2 = - ((long) (SYSCLK/BAUDRATE)/32);
       TMR2 = RCAP2;
       TR2= 1;                             // Start Timer2
       SCON = 0x50;                        // 8-bit variable baud rate;
       RX_Ready = 0;                       // Flag showing that UART can receive
       ES  = 1;
    }
    
    
    
    
    void main()
    {
            unsigned char x;
            unsigned char mybyte;
            unsigned char getChar;
            x=0;                            // Set as Input
    
            while(1)
                    {
                            LCD_init();
                            lcdCommand(0x01);
                            lcdCommand(0x02);
                            LCD_Print();
                            WDTCN = 0xDE;                       // Disable watchdog timer
                            WDTCN = 0xAD;
                            PORT_Init ();                       // Initialize crossbar and GPIO
                            UART0_Init ();                      // Initialize UART0
                            EA = 1;                                                         //interrupts are enabled
                            mybyte=SBUF;
                            getChar=SBUF;
                            while(RI==0);
                            RI=0;
                    }
    
    
    }
    
    
    
    
    
    
    I can't place the LCD_PRINT below PORT_Init (); and UART0_Init (); as it will not appear any character.
    So i put a while loop as it will return back and capture the getChar and display but this is not the case.
    The LCD_PRINT is working pefectly as i type 0x41 and it will appeared an A in the watch window.
    At the moment, i was sending a character 'K' over to the receiver
    //getChar=0x4b 'K' on watch window

Reply
  • Sorry, i will look clearly on the preview before i post out.
    Here you go.

    #include<f200.h>
    #include <stdio.h>
    #define RS P15
    #define RW P16
    #define E P17

    sfr16 RCAP2 = 0xCA; // Timer2 capture/reload
    sfr16 TMR2 = 0xCC; // Timer2

    #define BAUDRATE 9600 // Baud rate of UART in bps
    #define SYSCLK 110592000L // SYSCLK in Hz

    void PORT_Init (void);
    void UART0_Init (void);
    unsigned char RX_Ready =0;

    void delay(unsigned long duration)
    {
            while((duration--)!=0);
    }
    


    void setSystem();

    void strobe(unsigned char lcd_data)
    {
            E=1;
            delay(150);
            E=0;
            delay(150);
    }
    

    void LCD_init()
    {
      unsigned char x;
    
      for (x=0;x<3;x++)
       {
           P3=0x30;
           RS=0;
           RW=0;
           strobe();
           delay(1500);
        }
           P3=0x38;
           strobe();
           P3=0x0c;
           strobe();
           P3=0x01;
           strobe();
           P3=0x02;
           strobe();
    }
    


    //----- LCD Character Print routine --------

    void LCD_Print(unsigned char x)
    {
            P3 = x;
            RS = 1;
            RW=0;
            E=1;
            strobe(0x01);
    }
    


    //----- LCD Command ----------

    void lcdCommand(unsigned char x){
            P3 = x;
            RS = 0;
            RW=0;
            strobe(0x01);
    }
    
    void PORT_Init (void)
    {
       PRT0MX = 0x01;                      // Enable UART0
       PRT2MX = 0x80;                      // Enable global weak pull-up
       PRT0CF = 0x02;                      // RX is push-pull
    }
    

    void UART0_Init (void)
    {
       CKCON = 0x20;                       // Timer2 uses the system clock
       T2CON = 0x34;                       // Timer2 used for TX and RX, enabled
       RCAP2 = - ((long) (SYSCLK/BAUDRATE)/32);
       TMR2 = RCAP2;
       TR2= 1;                             // Start Timer2
       SCON = 0x50;                        // 8-bit variable baud rate;
       RX_Ready = 0;                       // Flag showing that UART can receive
       ES  = 1;
    }
    
    
    
    
    void main()
    {
            unsigned char x;
            unsigned char mybyte;
            unsigned char getChar;
            x=0;                            // Set as Input
    
            while(1)
                    {
                            LCD_init();
                            lcdCommand(0x01);
                            lcdCommand(0x02);
                            LCD_Print();
                            WDTCN = 0xDE;                       // Disable watchdog timer
                            WDTCN = 0xAD;
                            PORT_Init ();                       // Initialize crossbar and GPIO
                            UART0_Init ();                      // Initialize UART0
                            EA = 1;                                                         //interrupts are enabled
                            mybyte=SBUF;
                            getChar=SBUF;
                            while(RI==0);
                            RI=0;
                    }
    
    
    }
    
    
    
    
    
    
    I can't place the LCD_PRINT below PORT_Init (); and UART0_Init (); as it will not appear any character.
    So i put a while loop as it will return back and capture the getChar and display but this is not the case.
    The LCD_PRINT is working pefectly as i type 0x41 and it will appeared an A in the watch window.
    At the moment, i was sending a character 'K' over to the receiver
    //getChar=0x4b 'K' on watch window

Children