PIC Microcontroller USART (Asynchronous ) transmission Steps

It is necessary to follow some steps inorder to implement asynchronous transmission on PIC microcontrollers. And these steps are summarized below:
  • Initialize the SPBRG register for the appropriate baud rate. In the case high speed baud rate is rquired, set bit BRGH.
  • Dont forget to enable the asynchronous serial port by clearing bit SYNC and setting bit SPEN.
  • For interrupt based transmission enable bit TXIE.
  • For 9-bit transmission is desired, then set transmit bit TX9.
  • Enable the transmission by setting bit TXEN, which will also set bit TXIF.
  • If 9-bit transmission is selected, the ninth bit should be loaded in bit TX9D.
  • Load data to the TXREG register (starts transmission). It is to be noted, transmission starts immediately after  TXREG is loaded.
  • If using interrupts, ensure that GIE bit and PEIE bit (bits 7 and 6 of the INTCON register) are set.
Details to follow!

16:30 | Posted in , , , , , | Read More »

AVR based Multiple Input Digital Data Acquisition System using SDHC Card

Contributed by:
S/LT KAMRAN   (NUST)                      
Mr. KASHIF ALI (NUST) - Trainee Engineer at P&G
Report available only for educational purpose. 

Download the Project Report :

ABSTRACT

‘DATA   ACQUISITION SYSTEM’ is a system in which we have considered a scenario of a ship’s bridge in which different consoles are getting different data which is then manipulated and used accordingly. Our plan was to develop such a prototype system which would be getting data from different sensors simultaneously. The data is then stored in SDHC card which is being used first time in PNEC.

            GUI has also been made which would be showing different graphs of different data of different time. We have made GUI in C sharp which is also not very common here. We got so many hindrances in its making but with continuous efforts and some guideline from Mr Sajid from IIEE university helped us a lot to accomplish this task.

This system will be helpful for the OOW to monitor and control the data and then after analyzing situation, he may take the necessary steps properly

 AIM OF THE PROJECT

Our aim of the project is to design such a digital system which would be having multiple inputs and the data coming from these inputs is stored in the SDHC card (of huge memory). Once the data is stored in this memory card then it can be retrieved as well in form of graph. For this specific purpose we have made a GUI (graphical user interface) which made the data display in a required manner.
                                                                                                              
SCOPE OF THE PROJECT

Once the ship is in the sea, it needs to keep the record of different data coming from different sensors. For this purpose ship’s log is to be maintained, which is keeping the data of different time. These all are in physical form and also done manually, which is quite time taking. In any case of emergency it can be burnt or misplaced as well and can cause a lot of trouble at the time of requirement.

Normally, data acquisition and then keeping it for further use is also very much necessary almost in every part of field. Industries which are of critical nature or performing continuous processes at fields may require data storing as well.

So, keeping this scenario in mind we tried to advance this system with the help of some reliable sources. Here our idea is to design such a prototype system in which different sensors are installed and the digital data is being stored in SDHC card, then using serial communication it is connected with computer. GUI has also been made through which data of any installed sensor can be extracted and seen. This system is keeping the record of different sensors at the same time and can be used at any time in future for further use.

Download the Project Report  :

14:13 | Posted in , , , | Read More »

PIC Microcontroller based Intelligent Communication Device for the selection of low cost network using GSM and Telephony technology - Report

Contributed by:
S/LT ABDULLAH NAVEED   (NUST)                      
S/LT WASEEM SADIQ (NUST)


Download the Project Report :



         Download Schematics


ABSTARCT

Mobile phone in Pakistan has rapidly grown in to a commodity that everyone likes to possess. From the very beginning, the setup of mobile networks in Pakistan has been decentralized due to the reluctance of the government based telecommunication set up to step into this field. The other network phenomenon has been a serious hinge in the economical use of the mobile phone .This very problem has provided the motivation for this project. This has led to the design of a smart device which does the hard work for the user that it automatically selects the same network SIM which you are going to call. This results in the feasibility that you don’t have to physically replace the SIM leading to the economical conservation because when so ever an individual is making a cal, he does it within the network without manually doing it.

As the name indicates this project is aimed to provide communication at low cost. It will provide communication between the similar networks thus saving the other network call charges, for example if user wants to call a ufone number this device will direct this call via ufone connection.
This is just the beginning and our attempt is quite humble in this regard. But the efforts put in this regard may prove to be a solid base for the future work to be carried out in this domain. Scientific advancements in the field of telecommunication are by leaps and bounds and this project is a chain to that.

13:25 | Posted in , , | Read More »

How to Interface and Program Touch Screen Controller (MXB7843) with Microcontroller (PIC18F452) ? Tutorial

For newbies, please refer to:
Overview of MXB7843 interfacing with Microcontroller


First of all take a look at the schematic of the interfacing circuitry :






In-order to interface touch controller MXB7843 with the Microcontroller you only need to do 4 or 5 connections apart from the coding. Here is the general concept :


I assume that my readers are well aware of SPI communication. (However for newbies, here is some good stuff  on "SPI Tutotial" ).

Timing diagrams of SPI interface with MX7843 is given below:  


Touch screen controller gives the coordinates of X axis and Y axis when touch screen is touched. Interrupt is generated at the MXB7843 PENIRQ pin which tells the microcontroller that screen has been touched thereafter the controller send control bytes to it get the coordinates.Datasheet explain the algorithm to get the coordinates correctly. The procedure is given below:
  • Set up the control byte and call it TB. TB should begin with  the format: 1XXXXXXX binary, where X denotes the particular channel, selected conversion mode
  • Use a general-purpose I/O line on the CPU to pull CS low
  •  Transmit TB and simultaneously receive a byte; call it RB1.
  • Transmit a byte of all zeros ($00 hex) and simultaneously receive byte RB2.
  • Transmit a byte of all zeros ($00 hex) and simultaneously receive byte RB3.
  • Pull CS high.
As far as the control byte is considered, here are the options that one can play around with it :




By now, the formation of control byte remain no more an issue. Once the control byte is formed, what left is the coding, which is explained below for PIC18F452 Microcontroller, developed in C language on C18 compiler with MPLAB as IDE.


This code for touch screen has been designed for the background shown below : 




////////////////////////////////////////////////////////////////////////////////
//   PROJECT:       CONTROL OF ELECTRIC APPLIANCES (SLIDER CONTROL FOR RMS) WITH TOUCH PANEL INTERFACE



//   GROUP MEMBERS:   
//
//   1. Muhammad Asif        2.  Ahmed Fawad       3.  MUHAMMAD Ahmed 
//
//   
//  Code Includes:      TOUCH SCREEN INTERFACING WITH USART
//
//  Dated:  22 APR 2011
//
////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////
//          INCLUSION OF DIRECTORIES / CRYSTAL INITIALIZATION /    MACROS
/////////////////////////////////////////////////////////////////////////////////




#include<p18F452.h>
#include<p18cxxx.h>
#include<delays.h>
#include<timers.h>
#include<spi.h>
#include<usart.h>
#pragma config OSC=HSPLL , OSCS=OFF
#pragma config BORV=45 , PWRT = ON
#pragma config BOR=ON , WDT =OFF
#pragma config DEBUG=OFF, LVP=OFF , STVR=OFF


#define CS LATCbits.LATC1
#pragma code INT_1 = 0x08


///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////




//                    FUNCTION DECLARATIONS




//////////////////////////////////////////////////////////////////////////////




void INTT ();
unsigned char write(unsigned char);
void newline(void);




//////////////////////////////////////////////////////////////////////////////


unsigned char load_select=0;
unsigned char rms_control=0;
unsigned char tx_byte1=0;
unsigned char tx_byte2=0;


//////////////////////////////////////////////////////////////////////////////


         void INT_1 (void)
         {
           _asm
             goto INTT //jump to interrupt routine
           _endasm
         }
         
         #pragma code
         #pragma interrupt INTT


////////////////////////////////////////////////////////////////////////////////////////
//                     INTEERUPT SERVICE ROUTINE
///////////////////////////////////////////////////////////////////////////////////////


   void INTT ()
   {   
   unsigned char dig1,dig2,dig3,dig4,tmp,i,j,k,p,q,temp;   
   unsigned char x;
   unsigned char y; //VARIABLE DECLARATONS
   
   if(INTCONbits.INT0IF)
//   if(INTCON3bits.INT1IF)
   { 
   




while(1)
{
            OpenSPI(SPI_FOSC_64,MODE_00,SMPEND);    // OPENS SPI CONNECTION
                  
                  CS=0;                     // ENABLE MXB7843
      
                  Delay10TCYx(1);               // DELAY
   
                  temp=write(0b10010000);         //  CONTROL BYTE TO RETRIEVE X CORDINATES
                  Delay10TCYx(10);
   
                  x=write(0);
                  Delay10TCYx(10);
   
                  p=write(0);
                  Delay10TCYx(10);
   
                  CS=1;
                  Delay10TCYx(10);
                  CS=0;
   
                  Delay10TCYx(1);
   
                  temp=write(0b11010000);         //   CONTROL BYTE TO RETRIEVE Y CORDINATES
                  Delay10TCYx(10);
               
                  y=write(0);
                  Delay10TCYx(10);
   
                  q=write(0);
                  Delay10TCYx(10);
   
                  CS=1;                     // PULL CS HIGH
   
            CloseSPI();                        //  CLOSE SPI                  
   if(x==0||y==0)
  break;
else 
   putrsUSART("\033[2J");                          // CLEARS THE HYPER-TERMINAL
   
      
      Delay10TCYx(1);


putrsUSART("*** TOUCH SCREEN INTERRUPTED *** ");
   
      newline();
      newline();
   
      Delay10TCYx(1);


      putrsUSART("Co-ordinates = ");


//putrsUSART("*** TOUCH SCREEN INTERRUPTED *** ");
//   
//      newline();
//      newline();
//   
//      Delay10TCYx(1);
//
//      putrsUSART("Co-ordinates = ");
   
     
///////////////////////////////////////////////////////////////////////////
//               DECIMAL  --  BCD  --  ASCII  -- X - CORDINATES
///////////////////////////////////////////////////////////////////////////   
   
   
   dig1=x/1000+48;
   tmp=x%1000;
   dig2=tmp/100+48;
   tmp=tmp%100;
   dig3=tmp/10+48;
   dig4=tmp%10+48;
   
////////////////////////  TRANSMIT X CORDINATES VIA USART   //////////////   
                  
                  TXREG=40;
                  while(TXSTAbits.TRMT==0);
                  TXREG=dig1;
                  while(TXSTAbits.TRMT==0);
                  
                  TXREG=dig2;
                  while(TXSTAbits.TRMT==0);
                  
                  TXREG=dig3;
                  while(TXSTAbits.TRMT==0);
   
                  TXREG=dig4;
                  while(TXSTAbits.TRMT==0);
                  
                  TXREG=44;
                  while(TXSTAbits.TRMT==0);
                  
///////////////////////////////////////////////////////////////////////////
//               DECIMAL  --  BCD  --  ASCII  -- Y - CORDINATES
///////////////////////////////////////////////////////////////////////////   


                  
   
   dig1=y/1000+48;
   tmp=y%1000;
   dig2=tmp/100+48;
   tmp=tmp%100;
   dig3=tmp/10+48;
   dig4=tmp%10+48;
                  
////////////////////////  TRANSMIT Y CORDINATES VIA USART   //////////////   


            
                  TXREG=dig1;
                  while(TXSTAbits.TRMT==0);
                  
                  TXREG=dig2;
                  while(TXSTAbits.TRMT==0);
                  
                  TXREG=dig3;
                  while(TXSTAbits.TRMT==0);
   
                  TXREG=dig4;
                  while(TXSTAbits.TRMT==0);
   
                  TXREG=41;
                  while(TXSTAbits.TRMT==0);
                  
               newline();
   
///////////////////////////////////////////////////////////////////////////
//              CO-ORDINATES MAPPING / CALCULATONS
///////////////////////////////////////////////////////////////////////////   
   
   if(x<74&&y<50)
   {
   putrsUSART("DEVICE 1 IS SELECTED");
   newline();
   putrsUSART("RMS VOLTAGE PERCENTAGE  :   ");


//          if(x<72&&x>60&&y>=39)
//         {
//         putrsUSART("****TOGGLED****");
//         load_select=0b000;
//         rms_control=0b1111;
//         }




         if(x<=49&&y<50)
         {
         putrsUSART("****0****");
         load_select=0b1100;
         rms_control=0b0000;
         }


         else    if(x==50&&y<50)
         {
         putrsUSART("****6****");   
         load_select=0b1100;
         rms_control=0b0001;
         }
      
         else    if(x==51||x==52&&y<50)
         {
         putrsUSART("****12****");
         load_select=0b1100;
         rms_control=0b0010;
         }         


         else  if(x==53&&y<50)
         {
         putrsUSART("****18****");
         load_select=0b1100;
         rms_control=0b0011;
         }         


         else    if(x==54||x==55&&y<50)
         {
         putrsUSART("****26****");
         load_select=0b1100;
         rms_control=0b0100;
         }         


         else   if(x==56&&y<50)
         {
         putrsUSART("****30****");
         load_select=0b1100;
         rms_control=0b0101;
         }         


         else   if(x==57||x==58&&y<50)
         {
         putrsUSART("****36****");   
         load_select=0b1100;
         rms_control=0b0110;
         }      


         else   if(x==59&&y<50)
         {
         putrsUSART("****42****");
         load_select=0b1100;
         rms_control=0b0111;
         }         


         else   if(x==60||x==61&&y<50)
         {
         putrsUSART("****48****");
         load_select=0b1100;
         rms_control=0b1000;
         }   
   
         else   if(x==62&&y<50)
         {
         putrsUSART("****54****");   
         load_select=0b1100;
         rms_control=0b1001;
         }
   
         else   if(x==63||x==64&&y<50)
         {
         putrsUSART("****60****");
         load_select=0b1100;
         rms_control=0b1010;
         }   
   
         else   if(x==65&&y<50)
         {
         putrsUSART("****66****");
         load_select=0b1100;
         rms_control=0b1011;
         }   
   
         else   if(x==66||x==67&&y<50)
         {
         putrsUSART("****72****");
         load_select=0b1100;
         rms_control=0b1100;
         }   
   
         else   if(x==68&&y<50)
         {
         putrsUSART("****78****");
         load_select=0b1100;
         rms_control=0b1101;
         }   
      
         else    if(x==69||x==70&&y<50)
         {
         putrsUSART("****84****");
         load_select=0b1100;
         rms_control=0b1110;
         }


         else    if(x==71||x==72||x==73&&y<50)
         {
         putrsUSART("****96****");
         load_select=0b1100;
         rms_control=0b1111;
         }
      


   }
   else if(x<74&&y>49)
   {
   putrsUSART("DEVICE 2 IS SELECTED");
   newline();
   putrsUSART("RMS VOLTAGE PERCENTAGE  :   ");


//          if(x<73&&y<=70)
//         {
//         putrsUSART("****TOGGLED****");
//         load_select=0b001;
//         rms_control=0b1111;
//         }


        


         if(x==36||x==37&&y>49)
         {
         putrsUSART("****0****");
         load_select=0b1101;
         rms_control=0b0000;
         }


         else    if(x==38||x==39&&y>49)
         {
         putrsUSART("****6****");
         load_select=0b1101;
         rms_control=0b0001;
         }   
      
         else    if(x==40||x==41&&y>49)
         {
         putrsUSART("****12****");
         load_select=0b1101;
         rms_control=0b0010;
         }         


         else  if(x==42||x==43&&y>49)
         {
         putrsUSART("****18****");
         load_select=0b1101;
         rms_control=0b0011;
         }         


         else    if(x==44||x==45&&y>49)
         {
         putrsUSART("****26****");
         load_select=0b1101;
         rms_control=0b0100;
         }         


         else   if(x==46||x==47&&y>49)
         {
         putrsUSART("****30****");   
         load_select=0b1101;
         rms_control=0b0101;
         }      


         else   if(x==48||x==49&&y>49)
         {
         putrsUSART("****36****");
         load_select=0b1101;
         rms_control=0b0110;
         }         


         else   if(x==50||x==51&&y>49)
         {
         putrsUSART("****42****");
         load_select=0b1101;
         rms_control=0b0111;
         }         


         else   if(x==52||x==53&&y>49)
         {
         putrsUSART("****48****");
         load_select=0b1101;
         rms_control=0b1000;
         }   
   
         else   if(x==54||x==55&&y>49)
         {
         putrsUSART("****54****");
         load_select=0b1101;
         rms_control=0b1001;
         }   
   
         else   if(x==56||x==57&&y>49)
         {
         putrsUSART("****60****");
         load_select=0b1101;
         rms_control=0b1010;
         }   
   
         else   if(x==58||x==59&&y>49)
         {
         putrsUSART("****66****");
         load_select=0b1101;
         rms_control=0b1011;
         }   
   
         else   if(x==60||x==61&&y>49)
         {
         putrsUSART("****72****");
         load_select=0b1101;
         rms_control=0b1100;
         }   
   
         else   if(x==62||x==63&&y>49)
         {
         putrsUSART("****78****");
         load_select=0b1101;
         rms_control=0b1101;
         }   
      
         else    if(x==64||x==65&&y>49)
         {
         putrsUSART("****84****");
         load_select=0b1101;
         rms_control=0b1110;
         }


         else    if(x>65&&x<74&&y>49)
         {
         putrsUSART("****96****");
         load_select=0b1101;
         rms_control=0b1111;
         }


   }
   
   else if(x>73&&x<81&&y<37)
   {
   putrsUSART("DEVICE 1 IS TURNED OFF ");
   newline();
     
         load_select=0b0000;
         rms_control=0b1111;
   }


   else if(x>73&&x<81&&y>36&&y<58)
   {
   putrsUSART("DEVICE 1 IS TURNED ON ");
   newline();
     
         load_select=0b1000;
         rms_control=0b1111;
   }


   else if(x>73&&x<81&&y>57&&y<74)
   {
   putrsUSART("DEVICE 2 IS TURNED OFF ");
   newline();
     
         load_select=0b0001;
         rms_control=0b1111;
   }


   else if(x>73&&x<81&&y>73)
   {
   putrsUSART("DEVICE 2 IS TURNED ON ");
   newline();
     
         load_select=0b1001;
         rms_control=0b1111;
   }


  else if(x>80&&y<37)
   {
   putrsUSART("DEVICE 3 IS TURNED OFF ");
   newline();
     
         load_select=0b0010;
         rms_control=0b1111;
   }
   
    else if(x>80&&y>36&&y<58)
   {
   putrsUSART("DEVICE 3 IS TURNED ON ");
   newline();
     
         load_select=0b1010;
         rms_control=0b1111;
   }


   else if(x>80&&y>57&&y<74)
   {
   putrsUSART("DEVICE 4 IS TURNED OFF ");
   newline();
     
         load_select=0b0011;
         rms_control=0b1111;
   }
  


   else if(x>80&&y>73)
   {
   putrsUSART("DEVICE 4 IS TURNED ON ");
   newline();
     
         load_select=0b1011;
         rms_control=0b1111;
   }
   
   //Delay10TCYx(10);
   


   newline();
   newline();








////////////////////////////////////WHAT TO TRANSMIT OVER ETHERNET////////////////////////////////


PORTD=(rms_control<<4)|(load_select);






////////////////////////////////////////////////////////////////////////


}
   
/////////////////////////////////////////////////////////////////////////   
   
//   INTCON3bits.INT1IF=0;
INTCONbits.INT0IF=0;
    }
}
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
//                     INTERRUPT ROUTINE ENDED
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////




/////////////////////////////////////////////////////////////////////////
//                             MAIN - FUNCTION
////////////////////////////////////////////////////////////////////////
void main()




{


unsigned int temp;
   CS=1;
    /////////////////////////INTERRUPT INITIALIZATION///////////////////   
//                  INTCON = 0x80;
//                  INTCON2bits.INTEDG1=0;
//                  INTCON3bits.INT1IE=1;
//                  INTCON3bits.INT1IF=0;
//                  INTCON2bits.RBPU=0;




                  INTCON = 0x80;
                  INTCON2bits.INTEDG0=0;
                  INTCONbits.INT0IE=1;
                  INTCONbits.INT0IF=0;
                  INTCON2bits.RBPU=0;


   //////////////////////PORT INITIALIZATION INITIALIZATION///////////
  




   TRISB=0b11111111;
   TRISD=0x00;
   TRISC=0b10010000;








   ///////////////////////USAER INITIALIZATION///////////////////////
   RCSTAbits.SPEN=1;
   TRISCbits.TRISC6=0;
   TRISCbits.TRISC7=1;
   TRISCbits.TRISC5=0;
   TXSTA=0x20;
   SPBRG=32;


   Delay10TCYx(1);






            OpenSPI(SPI_FOSC_64,MODE_00,SMPEND);    // OPENS SPI CONNECTION
                  
                CS=0;                     // ENABLE MXB7843
      
                  Delay10TCYx(1);               // DELAY
   
                  temp=write(0b10010000); 


   CS=1;      
   
CloseSPI();




while(1);


}




/////////////////////FUNCTIONS DEFINITION////////////////////////////


      unsigned char write(unsigned char data_out)
      {      
           PIR1bits.SSPIF = 0;            // Clear interrupt flag
           SSPCON1bits.WCOL = 0;         //Clear any previous write collision
          SSPBUF = data_out;              // write byte to SSPBUF register
           if ( SSPCON1 & 0x80 )           // test if write collision occurred
              return ( -1 );              // if WCOL bit is set return negative #
           else
                                   // while( !SSPSTATbits.BF );  // wait until bus cycle complete 
         while( !PIR1bits.SSPIF );        // wait until bus cycle complete  
           
         return (SSPBUF); 
      }




      void newline(void)
      {
         TXREG=13;
         while(TXSTAbits.TRMT==0);
                  
         TXREG=10;
         while(TXSTAbits.TRMT==0);
      }




Download the SOURCE CODE here. You can edit the source code according to your need !

11:55 | Posted in , , , | Read More »

Labels

Recently Commented

Recently Added