i'm doin a project in which i'm supposed to interface 8051 microcontroller wid a gsm module 2 send sms... the 8051 microcontroller is a silabs development kit and the gsm module is from multi tech. I'm now supposed 2 write a programme in which after i debug and run it should send a simple msg. I have written most of the code but i'm facin a major problem can some 1 help me! thanks a lot.
//----------------------------------------------------------------------------- // Transmit Routine //-----------------------------------------------------------------------------
void Transmit(char ch) // *ch shows the pointer the array {
// int xxx; // xxx=0; while (ch!='\0') // last character of array wont be null { SBUF=ch; // transmit array at SBUF while(TI==0); // stays until characters transmitted TI=0; // Ready to transmit next. ch++;
// ttt[xxx+3]=1; // xxx++; // LED=~LED; } }
//----------------------------------------------------------------------------- // Receive Routine //-----------------------------------------------------------------------------
unsigned char Receive() { while(RI==0); // RI=0; // return SBUF;
}
//----------------------------------------------------------------------------- // CheckOK //-----------------------------------------------------------------------------
void CheckOK_01() {
for(k=0;k<8;k++) { Receive(); RI=0;
// OK[k]=SBUF; if(k==5) { OK[5]=SBUF; } if(k==6) {
OK[6]=SBUF; }
if(OK[5]=='O' && OK[6]=='K') ok1=1; else ok1=0;
} void CheckOK_02() {
for(k=0;k<15;k++) { Receive(); RI=0; // OK[k]=0; OK[k]=SBUF;
if(k==13) { OK[k-13]=SBUF; } if(k==14) {
OK[k-13]=SBUF; }
} if(OK[0]=='O' && OK[1]=='K') ok2=1; else ok2=0;
void CheckOK_03() {
for(k=0;k<30;k++) { Receive(); RI=0; // OK[k]=0; OK[k]=SBUF;
// if(k==25) } // OK[0]=SBUF; // }
// } // if(OK[25]=='>') // ok3=1; else // ok3=0;
} void SendChar(unsigned char b) {
SBUF=b; while(TI==0); TI=0; }
//----------------------------------------------------------------------------- // Initialization Subroutines //-----------------------------------------------------------------------------
//----------------------------------------------------------------------------- // OSCILLATOR_Init //----------------------------------------------------------------------------- // // Return Value : None // Parameters : None // // This function initializes the system clock to use an external 22.1184MHz // crystal. // //----------------------------------------------------------------------------- void OSCILLATOR_Init (void) { int i; // Software timer
OSCICN |= 0x80; // Enable the missing clock detector
// Initialize external crystal oscillator to use 22.1184 MHz crystal
OSCXCN = 0x67; // Enable external crystal osc.
for (i = 0; i < 256; i++); // Wait at least 1 ms while (!(OSCXCN & 0x80)); // Wait for crystal osc to settle
OSCICN |= 0x08; // Select external clock source OSCICN &= ~0x04; // Disable the internal osc.
//OSCICN = 0x14; // Select external clock source 00010100 //OSCICN &= ~0x04; // Disable the internal osc.
//----------------------------------------------------------------------------- // PORT_Init //----------------------------------------------------------------------------- // // Return Value : None // Parameters : None // // This function configures the crossbar and GPIO ports. // // Pinout: // // P0.0 digital push-pull UART TX // P0.1 digital push-pull UART RX //----------------------------------------------------------------------------- void PORT_Init (void) { XBR0 = 0x00; // Enable UART0 XBR1 = 0x00; XBR2 = 0x40; // Enable crossbar and weak pull-up
PRT0CF |= 0x03 ; // Set TX and RX tp P0.0 and P0.1 to push-pull respectively PRT1CF |= 0x40; }
//----------------------------------------------------------------------------- // UART0_Init Variable baud rate, Timer 2, 8-N-1 //----------------------------------------------------------------------------- // // Return Value : None // Parameters : None
// baud rate source. // //----------------------------------------------------------------------------- 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; // 9th bit ignored; RX enabled // clear all flags TX_Ready = 1; // Flag showing that UART can transmit // EA=1; // ES=1; // SERIAL PORT INTERRUPT ENABLE
// TI=1; }
"I have written most of the code but i'm facin a major problem can some 1 help me! thanks a lot."
1) Why don't you describe what your "major" problem is? Or are we expected to figure that out on our own?
2) What attempts have you made to figure out what the problem is?
3) The parts that may possibly be code seems like a copy/paste from other code. But everything you posted is posted unformatted, since you didn't read the information on how to post source code.
4) A large part of the code you seem to have written starts with // and isn't used. If it is intended to do something, then you need to remove the // infront of the lines. If the lines are not intended to do something, then you should remove them, and focus on the lines that means something. And instead add comments describing why you are doing different things, and what assumptions you have made.
which is very clearly stated:
www.danlhenry.com/.../keil_code.png
Why not repost your code, with the commented out lines removed. It'll probably end up being about a tenth of the size.
Your Receive function looks very minimalistic!
"with the commented out lines removed"
Indeed.
But be sure to use only spaces for layout - TABs will almost certainly not be interpreted correctly. (you can set uVision - and any other decent programmer's editor - to insert spaces when you press the TAB button).
Also be sure that your code builds cleanly - without warnings or errors - before you post it.
And give a clear description of what the code is intended to do, what it actually does, and what steps you have taken to debug it.
For debugging tips, see: www.8052.com/.../169331