serial programming plz explain

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kaushalneo
    New Member
    • Apr 2009
    • 3

    serial programming plz explain

    anyone can plz explain the code below....i have understood the basics of outortb and inportb but couldnt understand why and where specific hexcode values are used

    #include<stdio. h> //header//
    #include<conio. h> //header//
    #include<dos.h> //header//
    #include<graphi cs.h> //header//
    #include<proces s.h> //header//
    #include<time.h > //header//


    #define PORT1 0x3f8 //port address//

    unsigned char ca_data[25];

    void portinit(void)
    {
    outportb(PORT1 + 1,0);
    outportb(PORT1 + 3,0x80);
    outportb(PORT1 + 0,0x0c);
    outportb(PORT1 + 3,0x03);
    outportb(PORT1 + 4,0x0B);
    }

    char* dwt(){
    time_t t;
    time(&t);
    return ctime(&t);
    }

    void portclr(void)
    {
    char ch;
    while(inportb(P ORT1 + 5) & 1)
    {
    ch=inportb(PORT 1);
    }
    }


    void portread(int dnum,int timout)
    {
    int i=0,j=0;
    while((i < timout) && (j < dnum))
    {
    delay(1);
    if((inportb(POR T1 + 5) & 1))
    {
    if(j!=0)
    {
    ca_data[j]=inportb(PORT1) ;
    j++;
    }
    else
    {
    ca_data[j]=inportb(PORT1) ;
    if(ca_data[j]==0x65) //0x55
    j++;
    }

    }
    i++;
    }
    ca_data[dnum]=j;

    }



    void main(void)
    {
    int scan=0,device_1 =0,device_2=0,d num=12,timout=1 000;
    clrscr();
    printf("A Project on RFID System\n");
    do
    {
    do
    {
    portinit();
    do
    {
    portclr();
    do
    {
    //printf("Scannin g...........\n" );
    portread(dnum,t imout);
    }
    while(ca_data[dnum] < dnum);

    }while((ca_data[0]!=0x65)||(ca_da ta[1]!=0x99));
    printf("\nA Project on RFID System");
    printf("\nScann ing............ ............... .....");

    if(ca_data[3]==0x56)
    device_1=1;
    if(ca_data[3]==0x59)
    device_2=1;

    scan++;
    }while(scan<5);
    clrscr();
    printf("A Project on RFID System\n");
    printf("\nScann ing Results........ ...");
    printf("\nAvail able Devices........ ..");
    if(device_1==1)
    printf("\nDevic e Name________Ele ctronic Notebook");
    if(device_2==1)
    printf("\nDevic e Name________Vac uum Cleaner");
    printf("\nprese nt time________%s" ,dwt());
    if((device_1==0 )||(device_2==0 ))
    {
    printf("\n\nDev ices Missing........ ..");
    if(device_1==0)
    printf("\nDevic e Name________Ele ctronic Notebook");
    if(device_2==0)
    printf("\nDevic e Name________Vac uum Cleaner");
    sound(3000);
    printf("\nprese nt time________%s" ,dwt());
    printf("\nPress any key to Continue....... ..");
    getch();
    }
    printf("\n\n\n_ _______________ _______________ ___");


    device_1=0;
    device_2=0;
    scan=0;
    //delay(1000);
    }while(!kbhit() );

    }


    insight on below specific lines would be highly appreciated :

    }while((ca_data[0]!=0x65)||(ca_da ta[1]!=0x99));
    if(ca_data[j]==0x65) //0x55
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Originally posted by kaushalneo
    anyone can plz explain the code below....i have understood the basics of outortb and inportb but couldnt understand why and where specific hexcode values are used
    No we can't but I can explain why we can't. outportb writes directly to a memory location in the machine (you can't do this in WinXP, Vista or W7) so for instance I can see that your portinit function is writing 5 values to 4 separate locations in memory.

    Now from the function name I would assume that it is initialising the hardware at those memory locations (probably 1 piece of hardware with several registers) but without knowing what that piece of hardware is and having access to its technical specification neither I nor anyone else can say what writing those specific values to those specific registers will do.

    Comment

    • kaushalneo
      New Member
      • Apr 2009
      • 3

      #3
      thanks banfa for replying on this little piece of information that i have...


      sir i m only initialising the com port by these commands and not the hardware in the portinit function and all the hexcode values in them are there for the registers of the UART for specifying the baud rate, parity, stop bits etc.

      i took the pains to understand about those details and got them from the net...i must mention it took great pains to do even that

      but as of this program i just need help on specific data values that are being returned which ofcourse my hardware would send.

      for example i m referring to

      while((ca_data[0]!=0x65)||(ca_da ta[1]!=0x99));

      in this line i m unable to understand what 0x65 and 0x99 could possibly mean.


      similarly

      if(ca_data[3]==0x56)
      device_1=1;
      if(ca_data[3]==0x59)
      device_2=1;

      in this piece of code i m unable to get the significance of 0x56 and 0x59 and i suppose this would be the data that would come to my "COM port 1" and received from there.


      for instance in the portinit function the hex values refer to as follows :

      outportb(PORT1 + 3 , 0x80); /*Open Port*/
      outportb(PORT1 + 0 , 0x0C); /*Baud Rate 9600*/
      outportb(PORT1 + 3 , 0x03); /* 8 Bits, No Parity, 1 Stop Bit */
      outportb(PORT1 + 4 , 0x0B); /* Turn on DTR, RTS, and OUT2 */

      these all are pre-defined for the UART and do not refer to my hardware.


      any further help would be greatly acknowledged

      Comment

      • newb16
        Contributor
        • Jul 2008
        • 687

        #4
        Obviously, 0x56 and 0x59 are rfid tag ids stuck to notebook and vacuum. The hardware is supposed to issue 0x65 to its output and then up to 12 bytes (or until timeout expires), fourth of which is item's id. I'd rather start with reading this hardware's specs.

        Comment

        • kaushalneo
          New Member
          • Apr 2009
          • 3

          #5
          heyy thanks newb16...ur info helped a lot really....

          could u juz give me insight on 0x99 used in the same while loop.....

          thanks in advance...

          i ll try to geet the specs abt the hardware....and tell u the details and specifications of the same...

          Comment

          • praveenmude
            New Member
            • Sep 2008
            • 3

            #6
            comm port

            Hi the Port 1 defined with address 0x3F8 is the communications port COM 1 of the system, which is generally a printer port. You can find its specifications in any system from the system tools - system information. In the program, you are manipulating this COM 1 address and doing IO operations.

            Comment

            Working...