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
Your source code is illegible because you did not follow the clearly stated instruction on how to post source code: www.danlhenry.com/.../keil_code.png
Note: do not use TABs in your source code - use only spaces for indenting, etc.
Check the 'Preview' carefully before pressing the 'Post' button...
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
You didn't, did you?
The last 4 or so lines of code don't make sense to me, but I'm not going to spend any more time looking at it, just throw out a few questions.
Why are you reading SBUF when you don't know that anything is there? Shouldn't you look for RI or receive data ready first?
you while on RI==0? so there is where you wait for the next char? and then go back up and re-initialize everything at the top of the loop? Maybe I'm missing something, but that seems wrong.
Can you read out of SBUF twice? or does it clear the first time you read from it? I don't remember.
You're not doing anything with either of those variables anyway, except viewing them in the debugger. How does that data get to the LCD?
Using a delay loop in a high level language is frowned upon.
... because it will, quite likely, not do what you expect!
See: www.8052.com/.../162556