mc programs

Upload: beteley-teka

Post on 06-Apr-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/3/2019 MC Programs

    1/30

    1. Stepper Motor with HTI:#include //--------------Funtion declarationvoid MSDelay (unsigned int); //Delayvoid Send (unsigned char); //Serial data transfer

    void main(){

    unsigned char rdata; //Serially recieved data//-----------------The message

    unsigned char idata msg[8][30] = {" Sitec Electronics "," Stepper Motor Test Program ", Please Choose An Option ",

    "1. Clockwise Rotation ","2. AntiClockwise Rotation ",

    "3. Clockwise 'xx' RPM","4. Clockwise 'xx' RPM","5. Clockwise 'xx' RPM"};

    P1 = 00; //Set port 1 as outputTMOD = 0x20; //timer 1,mode 2(auto-reload)TH1 = -3; //9600 baud rateSCON = 0x50; //8-bit,1 stop, REN enabledTR1 = 1; //start timer 1

    while (1){//-------------Display message on hyper terminal

    unsigned char i,j;Send (0x0C);for (i=0;i

  • 8/3/2019 MC Programs

    2/30

    case (49):{while (RI==0) //keep doing the

    funtion until next command is recived{P0 =0x66; //Clockwise RotationMSDelay (1);P0 =0xCC;MSDelay (1);P0 =0x99;MSDelay (1);P0 =0x33;MSDelay (1);}break;}

    case (50):{while (RI==0){P0 =0x33; //AntiClockwise RotationMSDelay (1);P0 =0x99;MSDelay (1);P0 =0xCC;MSDelay (1);P0 =0x66;MSDelay (1);}break;

    }case (51):

    {while (RI==0){P0 =0x66; //Clockwise Rotation

    with reduced speedMSDelay (3);P0 =0xCC;MSDelay (3);P0 =0x99;MSDelay (3);

    P0 =0x33;MSDelay (3);}break;}

    case (52):{while (RI==0){

  • 8/3/2019 MC Programs

    3/30

    P0 =0x66; //Clockwise Rotationwith reduced speed

    MSDelay (6);P0 =0xCC;MSDelay (6);P0 =0x99;MSDelay (6);P0 =0x33;MSDelay (6);}break;}

    case (53):{while (RI==0){P0 =0x66; //Clockwise Rotation

    with reduced speedMSDelay (9);P0 =0xCC;MSDelay (9);P0 =0x99;MSDelay (9);P0 =0x33;MSDelay (9);}break;}

    }

    }

    }

    void MSDelay (unsigned int value) // Delay rouitne{

    unsigned int x,y;for (x=0;x

  • 8/3/2019 MC Programs

    4/30

    2. Stepper Motor with Matrix Keypad :

    #include

    //--------------Funtion declarationvoid MSDelay (unsigned int); //Delayunsigned char getkey ();unsigned char key=0;

    unsigned char idata keypad[4][4]= { 'A','C','X','X','1','2','3','X','X','X','X','X','X','X','X','X',};

    void main(){

    P1 = 00; //Set port 1 as output

    while (1){

    getkey (); //get data from matrix key padMSDelay(10);switch (key) //loop to respective subroutine

    {case ('C'):

    {while (key=='C') //keep doing

    the funtion until next command is recived{P0 =0x66; //Clockwise

    RotationMSDelay (1);P0 =0xCC;MSDelay (1);P0 =0x99;MSDelay (1);P0 =0x33;MSDelay (1);getkey ();}break;}

    case ('A'):{while (key=='A'){P0 =0x33;

    //AntiClockwise Rotation

  • 8/3/2019 MC Programs

    5/30

    MSDelay (1);P0 =0x99;MSDelay (1);P0 =0xCC;MSDelay (1);P0 =0x66;MSDelay (1);getkey ();}break;}

    case ('1'):{while (key=='1'){P0 =0x66; //Clockwise

    Rotation with reduced speedMSDelay (3);P0 =0xCC;MSDelay (3);P0 =0x99;MSDelay (3);P0 =0x33;MSDelay (3);getkey ();}break;}

    case ('2'):{

    while (key=='2'){P0 =0x66; //Clockwise

    Rotation with reduced speedMSDelay (6);P0 =0xCC;MSDelay (6);P0 =0x99;MSDelay (6);P0 =0x33;MSDelay (6);getkey ();

    }break;}

    case ('3'):{while (key=='3'){P0 =0x66; //Clockwise

    Rotation with reduced speed

  • 8/3/2019 MC Programs

    6/30

    MSDelay (9);P0 =0xCC;MSDelay (9);P0 =0x99;MSDelay (9);P0 =0x33;MSDelay (9);getkey ();}break;}

    }

    }}

    void MSDelay (unsigned int value) // Delay rouitne{

    unsigned int x,y;for (x=0;x

  • 8/3/2019 MC Programs

    7/30

    colloc = P2;colloc &= 0xf0;if (colloc != 0xf0)

    {rowloc = 0;break;

    }P2 = 0xfd;colloc = P2;colloc &= 0xf0;if (colloc != 0xf0)

    {rowloc = 1;break;

    }P2 = 0xfb;colloc = P2;colloc &= 0xf0;if (colloc != 0xf0)

    {rowloc = 2;break;

    }P2 = 0xf7;colloc = P2;colloc &= 0xf0;rowloc = 3;break;

    }//get

    the coloum pressesif (colloc == 0xe0) key = (keypad[rowloc][0]);else if (colloc == 0xd0) key = (keypad[rowloc][1]);else if (colloc == 0xb0) key = (keypad[rowloc][2]);else key = (keypad[rowloc][3]);

    return(key);}

  • 8/3/2019 MC Programs

    8/30

    3. ADC_Temperature

    #include

    sbit rd = P1^1; //Variables declaration for ADCsbit wr = P1^2;sbit intr = P1^3;sbit aen = P1^0;sfr mydata1 = 0xA0; //ADC data

    sfr ldata = 0x80; //Variables declaration for LCDsbit rs = P3^7;sbit rw = P3^6;sbit en = P3^5;sbit busy = P0^7;

    //--------------Funtion declaration

    void convert_display(unsigned char);//Hex to Binary converter void lcdcmd (unsigned char value); //LCD commandvoid lcddata (unsigned char value); //LCD datavoid lcdready (); //Initialization LCD 2 lines,5x7matrixvoid MSDealy(unsigned int itime); //Delay

    void main(){

    unsigned char value; //ADC data recived

    lcdcmd(0x38); //LCD commandlcdcmd(0x0e);lcdcmd(0x01);lcdcmd(0x06);lcdcmd(0x83);lcddata('T'); //LCD datalcddata('e');lcddata('m');lcddata('p');lcddata('e');lcddata('r');lcddata('a');

    lcddata('t');lcddata('u');lcddata('r');lcddata('e');lcddata('r');

    mydata1 = 0xff; //Set port 2 as inputldata = 0x00; //Set port 0 as output

  • 8/3/2019 MC Programs

    9/30

    //---------ADC routinewhile (1)

    {aen = 0; //enable ADCwr = 0; //Write=0wr = 1; //WR=1 L-TO-H TO START

    CONVERSIONwhile (intr == 1) ; //WAIT FOR END OF CONVERSIONrd = 0; //CONVERSION

    FINISHED,ENABLE RDvalue = mydata1; //READ THE DATAvalue = value - 114;lcdcmd(0xC7);

    convert_display(value);rd = 1; //MAKE RD=1 FOR NEXT ROUNDMSDealy(10);

    }}

    //----------------Hex to Binary convertion routinevoid convert_display(unsigned char value)

    {unsigned char x, d1, d2, d3, data1, data2, data3;x = value / 10; //divide by 10d1 = value % 10; //save low digit (reminder of division)d2 = x % 10;d3 = x / 10; //divide by 10 once moredata1 = d1 | 0x30; //make it ASCII and save LSBdata2 = d2 | 0x30;

    data3 = d3 | 0x30;

    lcddata(data3); //display converted output MSB firstlcddata(data2);

    lcddata(data1);return;

    }

    //--------------LCD commandvoid lcdcmd (unsigned char value)

    {lcdready(); //is LCD ready?

    ldata = value; //issue command coders = 0; //RS=0 for commandrw = 0; //R/W=0 to write to LCDen = 1; //E=1 for H-to-L pulseMSDealy(1);en = 0; //E=0 ,latch inreturn;

    }

  • 8/3/2019 MC Programs

    10/30

    //-------------LCD datavoid lcddata (unsigned char value)

    {lcdready(); //is LCD ready?ldata = value; //issue datars = 1; //RS=1 for datarw = 0; //R/W=0 to write to LCDen = 1; //E=1 for H-to-L pulseMSDealy(1);en = 0; //E=0, latch inreturn;

    }

    void lcdready (){

    busy = 1; //make P1.7 input portrs = 0; //RS=0 access command regrw = 1; //R/W=1 read command reg ;read command reg

    and check busy flagwhile (busy == 1) //stay until busy flag=0

    {en = 0; //E=1 for H-to-L pulseMSDealy(1);en = 1; //E=0 H-to-L pulse

    }return;

    }

    //------------Delay Routinevoid MSDealy(unsigned int itime)

    {unsigned int i,j;for (i=0;i

  • 8/3/2019 MC Programs

    11/30

    4. CALC_LCD

    #include sfr ldata = 0x80; //Variables declaration for LCD

    sbit rs = P3^7;sbit rw = P3^6;sbit en = P3^5;sbit busy = P0^7;

    //--------------Funtion declarationvoid convert_display(unsigned char);//Hex to Binary converter void MSDelay (unsigned int); //Delayvoid lcdcmd (unsigned char value);void lcddata (unsigned char value);void lcdready ();unsigned char getkey ();

    unsigned char j,countl,countr, key=0,Data1,Data2,Funct,Ans ; //Seriallyrecieved data

    //-----------------The messageunsigned char idata msg[11] = {"Calculator "};

    unsigned char idata keypad[4][4]= { '1','2','3','/','4','5','6','*','7','8','9','-','C','0','C','+',};

    void main(){while(key!='C'){

    lcdcmd(0x38);lcdcmd(0x0e);lcdcmd(0x01);lcdcmd(0x06);lcdcmd(0x83);

    //-------------Display message on lCD terminal

    for (j=0;j

  • 8/3/2019 MC Programs

    12/30

    do{

    getkey (); //get data from matrix key padMSDelay(10);Data1 = key;key = key & 0xF0;

    }while (key!=0x30);lcddata(Data1);

    do{

    getkey (); //get data from matrix key padMSDelay(10);Funct = key;key = key & 0xF0;

    }while (key!=0x20);lcddata(Funct);

    do{

    getkey (); //get data from matrix key padMSDelay(10);Data2 = key;key = key & 0xF0;

    }while (key!=0x30);lcddata(Data2);lcddata('=');

    Data1= Data1 & 0x0F;Data2= Data2 & 0x0F;

    switch (Funct) //loop to respective subroutine

    {case ('+'):{Ans = Data1 + Data2;convert_display(Ans);break;}case ('-'):{Ans = Data1 - Data2;convert_display(Ans);

    break;}case ('*'):{Ans = Data1 * Data2;convert_display(Ans);

    break;}

  • 8/3/2019 MC Programs

    13/30

    case ('/'):{Ans = Data1 / Data2;convert_display(Ans);

    break;}

    }}}}

    void MSDelay (unsigned int value) // Delay routine{

    unsigned int x,y;for (x=0;x

  • 8/3/2019 MC Programs

    14/30

    }return;

    }

    unsigned char getkey () // Routine to read matrix keyboard{

    unsigned char colloc, rowloc;TMOD = 0x20;TH1 = -3;SCON = 0x50;TR1 = 1;

    P2 = 0xff;do {

    P2 = 0x0f; //Wait untill all keys arereleased

    colloc = P2;colloc &= 0x0f;

    } while (colloc != 0x0f);

    do {do

    {MSDelay (1);colloc = P2;colloc &= 0x0f;

    } while (colloc == 0x0f); //Check whether any ket ispressed

    MSDelay (1);colloc = P2;

    colloc &= 0x0f; //Confirm whether anyket is pressed after delay

    } while (colloc == 0x0f); //to aviod spikes

    while(1){

    P2 = 0xfE; //get the rowpresses

    colloc = P2;colloc &= 0xf0;if (colloc != 0xf0)

    {

    rowloc = 0;break;

    }P2 = 0xfd;colloc = P2;colloc &= 0xf0;if (colloc != 0xf0)

    {rowloc = 1;

  • 8/3/2019 MC Programs

    15/30

    break;}

    P2 = 0xfb;colloc = P2;colloc &= 0xf0;if (colloc != 0xf0)

    {rowloc = 2;break;

    }P2 = 0xf7;colloc = P2;colloc &= 0xf0;rowloc = 3;break;

    }//get

    the coloum pressesif (colloc == 0xe0) key = (keypad[rowloc][0]);else if (colloc == 0xd0) key = (keypad[rowloc][1]);else if (colloc == 0xb0) key = (keypad[rowloc][2]);else key = (keypad[rowloc][3]);

    return(key);}

    //----------------Hex to Binary convertion routinevoid convert_display(unsigned char value)

    {

    unsigned char x, d1, d2, d3, data1, data2, data3;x = value / 10; //divide by 10d1 = value % 10; //save low digit (reminder of division)d2 = x % 10;d3 = x / 10; //divide by 10 once moredata1 = d1 | 0x30; //make it ASCII and save LSBdata2 = d2 | 0x30;data3 = d3 | 0x30;

    lcddata(data3); //display converted output MSB firstlcddata(data2);

    lcddata(data1);

    return;}

  • 8/3/2019 MC Programs

    16/30

  • 8/3/2019 MC Programs

    17/30

    rdata = SBUF; //get data recivedRI =0; //clear flag for next incoming

    dataswitch (rdata) //loop to respective subroutine

    {case (49):

    {while (RI==0) //keep doing the funtion

    until next command is recived{mtr_1 = 1; //Clockwise

    Rotationmtr_2 = 0;}

    break;}

    case (50):{while (RI==0)

    {mtr_1 = 0;mtr_2 = 1; //AntiClockwise

    Rotation}

    break;}

    case (51):{while (RI==0)

    {mtr_2 = 0;mtr_1 = 1;

    //Clockwise Rotation with PWM speed control

    MSDelay (5);mtr_1 = 0;MSDelay (5);}

    break;}

    case (52):{while (RI==0)

    {mtr_2 = 0;mtr_1 = 1;

    //Clockwise Rotation with PWM speed control

    MSDelay (1);mtr_1 = 0;MSDelay (20);}

    break;}

    case (53):{while (RI==0)

    {

  • 8/3/2019 MC Programs

    18/30

    mtr_2 = 0;mtr_1 = 1;

    //Clockwise Rotation with PWM speed controlMSDelay (1);mtr_1 = 0;MSDelay (40);}

    break;}

    }

    }

    }

    //------------Delay Routinevoid MSDelay (unsigned int value)

    {unsigned int x,y;for (x=0;x

  • 8/3/2019 MC Programs

    19/30

    unsigned char i,j,countl,countr, key=0,Data1='0',Data2='0',Funct,Ans ;//Serially recieved data

    //-----------------The messageunsigned char idata msg[9] = {"Floor No:"};

    unsigned char idata keypad[4][4]= { '1','2','3','X',

    '4','5','6','X',

    '7','8','9','X',

    'X','0','X','X',};

    void main(){

    lcdcmd(0x38);lcdcmd(0x0e);lcdcmd(0x01);lcdcmd(0x06);lcdcmd(0x80);

    //-------------Display message on hyper terminal

    for (j=0;j0;j--)

    {

  • 8/3/2019 MC Programs

    20/30

    lcdcmd(0x8E);lcddata('v');lcddata('v');MSDelay(30);lcdcmd(0x8E);lcddata(' ');lcddata(' ');MSDelay(30);}

    Data2--;lcdcmd(0x8b);lcddata(Data2);

    }

    }

    void up(){for(i=(Data1-Data2);i>0;i--)

    {for (j=3;j>0;j--)

    {lcdcmd(0x8E);lcddata('^');lcddata('^');MSDelay(30);lcdcmd(0x8E);lcddata(' ');lcddata(' ');MSDelay(30);}

    Data2++;lcdcmd(0x8b);lcddata(Data2);

    }

    }

    void MSDelay (unsigned int value) // Delay routine{

    unsigned int x,y;for (x=0;x

  • 8/3/2019 MC Programs

    21/30

    en = 0;return;

    }

    void lcddata (unsigned char value){

    lcdready();ldata = value;rs = 1;rw = 0;en = 1;MSDelay(1);en = 0;return;

    }

    void lcdready (){

    busy = 1;rs = 0;rw = 1;while (busy == 1)

    {en = 0;MSDelay(1);en = 1;

    }return;

    }

    unsigned char getkey () // Routine to read matrix keyboard{

    unsigned char colloc, rowloc;

    TMOD = 0x20;TH1 = -3;SCON = 0x50;TR1 = 1;

    P2 = 0xff;do {

    P2 = 0x0f; //Wait untill all keys arereleased

    colloc = P2;colloc &= 0x0f;

    } while (colloc != 0x0f);

    do { do{

    MSDelay (1);colloc = P2;colloc &= 0x0f;

    } while (colloc == 0x0f); //Check whether anyket is pressed

    MSDelay (1);colloc = P2;

  • 8/3/2019 MC Programs

    22/30

    colloc &= 0x0f; //Confirmwhether any ket is pressed after delay

    } while (colloc == 0x0f); //to aviod spikes

    while(1){

    P2 = 0xfE; //getthe row presses

    colloc = P2;colloc &= 0xf0;if (colloc != 0xf0)

    {rowloc = 0;break;

    }P2 = 0xfd;colloc = P2;colloc &= 0xf0;if (colloc != 0xf0)

    {rowloc = 1;break;

    }P2 = 0xfb;colloc = P2;colloc &= 0xf0;if (colloc != 0xf0)

    {rowloc = 2;break;

    }P2 = 0xf7;colloc = P2;

    colloc &= 0xf0;rowloc = 3;break;

    }

    //get the coloum pressesif (colloc == 0xe0) key = (keypad[rowloc][0]);else if (colloc == 0xd0) key = (keypad[rowloc][1]);else if (colloc == 0xb0) key = (keypad[rowloc][2]);else key = (keypad[rowloc][3]);

    return(key);}

    /*----------------Hex to Binary convertion routinevoid convert_display(unsigned char value)

    {unsigned char x, d1, d2, d3, data1, data2, data3;x = value / 10; //divide by 10d1 = value % 10; //save low digit (reminder of division)d2 = x % 10;d3 = x / 10; //divide by 10 once more

  • 8/3/2019 MC Programs

    23/30

    data1 = d1 | 0x30; //make it ASCII and save LSBdata2 = d2 | 0x30;data3 = d3 | 0x30;

    lcddata(data3); //display converted output MSB firstlcddata(data2);

    lcddata(data1);return;

    } */

    7. DAC with HTI #include //--------------Funtion declarationvoid MSDelay (unsigned int); //Delayvoid Send (unsigned char); //Serial data transfer

    void main()

    {unsigned char rdata; //Serially recieved data

    //-----------------The messageunsigned char xdata msg[8][29] = {"******Sitec Electronics******",

    " DAC InterfaceProgram ",

    "1. Ramp",

    "2. Rectangle Wave",

    "3. Sawtooth Wave ","4. Sine Wave ",

    "5. Square Wave ",

    "6. Triangle Wave "};unsigned char idata table[180] =

    {128,132,136,141,154,150,154,158,163,167,171,175,180,184,188, 192,195,199,203,206,210,213,216,220,223,226,228,231,234,236,

    238,241,243,244,246,247,248,249,250,251,252,253,254,255,255,

    255,255,255,254,254,253,252,251,249,246,244,243,241,238,236,

    234,231,228,226,223,220,216,213,210,206,203,199,195,192,188,

    184,180,175,171,167,163,158,154,150,145,141,136,132,128,

    123,119,114,110,105,101,97,92,88,84,80,75,71,67,64,60,56,52,

    49,45,42,39,35,32,29,27,24,21,19,17,14,12,11,9,7,6,4,3,2,1,1,0,0,0,0,

    0,0,0,0,1,1,2,3,4,6,7,9,11,12,14,17,19,21,24,27,29,32,35,39,42,45,49,

    52,56,60,64,67,71,75,80,84,88,92,97,101,105,110,114,119,123,128};

  • 8/3/2019 MC Programs

    24/30

    P0 = 00; //Set port 1 as outputTMOD = 0x20; //timer 1,mode 2(auto-reload)TH1 = -3; //9600 baud rateSCON = 0x50; //8-bit,1 stop, REN enabledTR1 = 1; //start timer 1

    while (1){//-------------Display message on hyper terminal

    unsigned char i,j;Send (0x0C);for (i=0;i

  • 8/3/2019 MC Programs

    25/30

    P0= i;}

    for (i=255;i>1;i--){P0= i;}

    }break;}

    case (53):{while (RI==0){MSDelay (50); //Square WaveP0 = 0xff;MSDelay (50);}break;}

    case (52):{while (RI==0){for (i=0;i

  • 8/3/2019 MC Programs

    26/30

    {SBUF = x;while (TI==0);TI=0;

    }

    8. 7 Segment with matrix Keypad#include sbit srck = P0^6 ;sbit ser = P0^5 ;sbit rck = P0^7 ;

    //--------------Funtion declarationvoid display(unsigned char); //Hex to Binary converter void MSDelay (unsigned int); //Delayunsigned char getkey ();

    unsigned char temp,numb,key=0; //Serially recieved data//-----------------The messageunsigned char idata keypad[4][4]= { '1','2','3','0',

    '4','5','6','0','7','8','9','0','0','0','0','0',};

    unsigned char idata disp[10] = { 0x40,0xcf,0xa4,0x30,0x19,0x12,0x02,0xf8,0x00,0x10 };

    void main(){while(1)

    {getkey();

    temp= key | 0x0F ;numb = disp [temp];display(numb);}

    }

    void MSDelay (unsigned int value) // Delay routine{

    unsigned int x,y;for (x=0;x

  • 8/3/2019 MC Programs

    27/30

    do {P2 = 0x0f; //Wait untill all keys are releasedcolloc = P2;colloc &= 0x0f;

    } while (colloc != 0x0f);

    do {do

    {MSDelay (1);colloc = P2;colloc &= 0x0f;

    } while (colloc == 0x0f); //Check whether any ket ispressed

    MSDelay (1);colloc = P2;colloc &= 0x0f; //Confirm whether any

    ket is pressed after delay} while (colloc == 0x0f); //to aviod spikes

    while(1){

    P2 = 0xfE; //get the rowpresses

    colloc = P2;colloc &= 0xf0;if (colloc != 0xf0)

    {rowloc = 0;break;

    }P2 = 0xfd;colloc = P2;

    colloc &= 0xf0;if (colloc != 0xf0)

    {rowloc = 1;break;

    }P2 = 0xfb;colloc = P2;colloc &= 0xf0;if (colloc != 0xf0)

    {rowloc = 2;break;

    }P2 = 0xf7;colloc = P2;colloc &= 0xf0;rowloc = 3;break;

    }//get

    the coloum pressesif (colloc == 0xe0) key = (keypad[rowloc][0]);

  • 8/3/2019 MC Programs

    28/30

    else if (colloc == 0xd0) key = (keypad[rowloc][1]);else if (colloc == 0xb0) key = (keypad[rowloc][2]);else key = (keypad[rowloc][3]);

    return(key);}

    //----------------7 segment displayvoid display(unsigned char value)

    {/* SER CON P2 ; serial outputSRCK CON P0 ; shift clockRCK CON P0 ; output latchDelay CON 100counter VAR Byte' -------------------------------------------------------------------------mainfor counter=0 to 255gosub Out595pause 100 ;Change to in/decrease speednextgoto main' -------------------------------------------------------------------------Out595:Shiftout SER,SRCK,MSBPRE,[counter\8] ; send pattern to 74hc595Pulsout RCK,8 ; latch outputs(min 8us) can be as little as 4usReturn */

    unsigned char bits;srck = 1;rck = 0;ACC = value;

    for (bits=0;bits> 1;

    }rck =1 ;srck =1 ;

    return;}

    9. ADC with LED#include

    sbit rd = P1^1; //Variables declaration for ADCsbit wr = P1^2;sbit intr = P1^3;sbit aen = P1^0;sfr mydata1 = 0xA0; //ADC data

  • 8/3/2019 MC Programs

    29/30

    sbit srck = P0^1 ;sbit ser = P0^2 ;sbit rck = P0^0 ;

    //--------------Funtion declarationvoid convert_display(unsigned char); //Hex to Binary converter void display(unsigned char);void MSDealy(unsigned int itime); //Delay

    void main(){

    unsigned char value; //ADC data recivedmydata1 = 0xff; //Set port 2 as input

    //---------ADC routinewhile (1)

    {aen = 0; //enable ADCwr = 0; //Write=0wr = 1; //WR=1 L-TO-H TO START

    CONVERSIONwhile (intr == 1) ; //WAIT FOR END OF CONVERSIONrd = 0; //CONVERSION

    FINISHED,ENABLE RDvalue = mydata1; //READ THE DATAvalue = value - 114;

    convert_display(value);rd = 1; //MAKE RD=1 FOR NEXT

    ROUNDMSDealy(10);

    }

    }

    //----------------Hex to Binary convertion routinevoid convert_display(unsigned char value)

    {unsigned char x, d1, d2, d3, data1, data2, data3;x = value / 10; //divide by 10d1 = value % 10; //save low digit (reminder of division)d2 = x % 10;d3 = x / 10; //divide by 10 once more

    display(0x3F);display(data3); //display converted output MSB first

    display(data2);display(data1);return;

    }

    //----------------7 segment displayvoid display(unsigned char value)

    {/* SER CON P2 ; serial outputSRCK CON P0 ; shift clock

  • 8/3/2019 MC Programs

    30/30

    RCK CON P0 ; output latchDelay CON 100counter VAR Byte' -------------------------------------------------------------------------mainfor counter=0 to 255gosub Out595pause 100 ;Change to in/decrease speednextgoto main' -------------------------------------------------------------------------Out595:Shiftout SER,SRCK,MSBPRE,[counter\8] ; send pattern to 74hc595Pulsout RCK,8 ; latch outputs(min 8us) can be as little as 4usReturn */

    unsigned char idata disp[10] ={ 0x40,0xcf,0xa4,0x30,0x19,0x12,0x02,0xf8,0x00,0x10 };

    unsigned char bits;srck = 1;rck = 0;ACC = disp [value];

    for (bits=0;bits> 1;

    }rck =1 ;srck =1 ;

    return;

    }

    //------------Delay Routinevoid MSDealy(unsigned int itime)

    {unsigned int i,j;for (i=0;i