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

Need help in C51 Programming

Hi, i'm pretty new to programming. I'm currently using Keil uvision to program AT89S4051 Microcontroller in C language. I'm trying to read bit by bit data from the I/O port every 50us and store it in an external memory bit by bit. However, i would want to store a bit then shift to next bit and store. After 8 bits, store on a new byte and for 300 bytes. Anyone could suggest a method on how to do that? My program is posted down below (it's probably full of mistakes) Thanks in advance.

#include <reg51.h>
sbit Tsignal = P1^2;                                              //Input Signal
sbit Learn = P1^3;
unsigned int i;
unsigned char xdata x[300];
unsigned char xdata y[300];


void timer0(void)
{
 TMOD = 0x01;                                                   //Timer0 , Mode 1
 TH0 = 0xFF;                                                    //Set timer to count from -46 = FFD2h
 TL0 = 0xD2;

 TR0 = 1;
 while(TF0==0);                                         //Turn on Timer0
 TF0 = 0;                               //Set Flag to 0;
 TR0 = 0;                                                           //Turn off Timer0
}
void main(void)
{
 Learn=0;
 if(Learn==1)                                             //If learn button is pressed, data as stored as sampling data
 {
  for(i=0;i<299;i++)                                    //Loop for 300 bytes
  {
   timer0();                                                    //Call timer0 function
   x[i] = Tsignal;                                              //Store Tsignal in x
  }
 }
  else                                                                   //When Learn button is not pressed, data is stored as
  {
   for(i=0;i<299;i++)                                         //Loop for 300 bytes
   {
    timer0();                                                    //Call timer0 function
        y[i] = Tsignal;                                          //Store Tsignal in y
   }
  }
}

Parents
  • Thank you Sir, for your reply. Your Sentence "Next thing - there is nothing magic about this processsor.", are you trying to say that this processor is really straight forward to program?

    So, for me to be able to store bit by bit then shift to next byte, i have to use bitshift till i stored all 8 bits. Then shift byte and continue the process?

    Regarding the 300 samples, i was trying to declare 300 bytes instead of bits. Well, my programming is seriously weak, so bear with my mistakes. So if i were to declare 300 bytes, it would mean that i will be storing my every bit data into every byte of data? If so, i will change it from 300 to 2400 as it will become 300bytes.

Reply
  • Thank you Sir, for your reply. Your Sentence "Next thing - there is nothing magic about this processsor.", are you trying to say that this processor is really straight forward to program?

    So, for me to be able to store bit by bit then shift to next byte, i have to use bitshift till i stored all 8 bits. Then shift byte and continue the process?

    Regarding the 300 samples, i was trying to declare 300 bytes instead of bits. Well, my programming is seriously weak, so bear with my mistakes. So if i were to declare 300 bytes, it would mean that i will be storing my every bit data into every byte of data? If so, i will change it from 300 to 2400 as it will become 300bytes.

Children