Skip to main content

Programmable Function Generator in C

 Works fine....


#include<reg51.h>
#include<string.h>

typedef unsigned char uchar;
uchar flag;
uchar count=0;
uchar cmd[10];
uchar sineLukup[]={    0x80,0x96,0x0ab,0x0c0,0x0d2,0x0e2,0x0ef,
                      0x0f8,0x0fe,0x0ff,0x0fe,0x0f8,0x0ef,0x0e2,
                       0x0d2,0x0c0,0x0ab,0x096,0x80,0x6a,0x54,
                       0x40,0x2e,0x1e,0x11,0x08,0x02,0x00,0x02,
                    0x08,0x11,0x1e,0x2e,0x40,0x54,0x6a,0x80};

code uchar rIDN[] = "PROGRAMMABLE FUCNTION GENERATOR";
code uchar rVER[] = "version 1.1";
code uchar rMODSET[] = "MODE SET SUCCESSFUL";
code uchar rCMDERR[]="CMDERR";

void sendResp(uchar *val,uchar cnt);

void sqrWav();
void sthWav();
void sinWav();
void triWav();

void (*wave)();

void delay01ms(uchar val);

void initProgram()
{
     EA=1;
    ES=1;
   
    SCON =0x50;
    TMOD=0x21;
    TH1 = 0x253;
    TL1 = 0X253;
    TR1 =1;   
   
    flag=1;   
       
}
void sqrWav()
{
     while( flag ){
        P0 = !P0;
        delay01ms(1);
    }
}


void delay01ms(uchar val)
{
    uchar i;
     for(i=0;i<val;i++){
         TH0=0x22;
        TL0=0x00;
        TF0=0;
        TR0=1;
        while(TF0!=1);
    }


}

void sthWav()
{    uchar i;
    while(flag){
        P0=i++;
    }
}


void sinWav()
{    uchar i=0;
    while(flag){
        for(i=0;i<37  ;i++){
            P0=sineLukup[i];
            delay01ms(1);
        }
    }
}


void triWav()
{    uchar i,TEMP;
    TI=0;
    while(flag){
            TEMP = 0;
        for(i=0;i<200;i++)       
            P0=TEMP++;   

            TEMP = 200 ;
        for(i=0;i<200;i++)       
            P0=TEMP--;               
       
    }
}

void processQry()
{
     if(!strncmp(cmd,"*IDN?",5)){
         sendResp(rIDN,31);
    }
    else if(!strncmp(cmd,":VER?",5)){
         sendResp(rVER,10);
    }
    else if(!strncmp(cmd,":MOD:SIN",8)){
         sendResp(rMODSET,19);
        wave = sinWav;
        flag=0;
    }
    else if(!strncmp(cmd,":MOD:SQR",8)){
         sendResp(rMODSET,19);
        wave = sqrWav;
        flag=0;
    }
    else if(!strncmp(cmd,":MOD:STH",8)){
         sendResp(rMODSET,19);
        wave = sthWav;
        flag=0;
    }
    else if(!strncmp(cmd,":MOD:TRI",8)){
         sendResp(rMODSET,19);
        wave = triWav;
        flag=0;
    }
    else{ 
         sendResp(rCMDERR,6);
    }
   
}

void sendSerial(uchar val)
{
     TI=0;
    SBUF = val;
    while(TI!=1);
}

void sendResp(uchar *val, uchar cnt)
{                 
    uchar i=0;
     for(i=0;i<cnt;i++){
         sendSerial(val[i]);
        delay01ms(1);
    }
    TI=0;             
}

void serialISR(void) interrupt 4
{
     if(RI==1)
    {   
        RI=0;
        cmd[count]=SBUF;
        count++;

        if(SBUF==13){
            processQry();
            count=0;
        }
    }
}

void main()
{
   initProgram();
   wave=sqrWav;
   while(1){
        EA=1;
        ES=1;
        flag=1;
        wave();
    }
   
}

Comments

Popular posts from this blog

Installing and Activating KEIL uVision

*** NOTE: Click on the images to view them in full resolution Download: Download Keil from the link below: Keil Latest Version Free download with keygen After Installation: 1. File -> License Management 2. Open Keygen from the folder where rar file is unpacked 3. Copy computer ID ( CID ) to clipboard 4. Paste CID in KEYGEN exe, Press generate, copy generated serial and paste in new license textbox of Licence management. *** NOTE: Click on the images to view them in full resolution

Average and Square Root Using 8085

AVERAGE OF N NUMBERS AIM:       To write an assembly language program that finds the average of N numbers and executes the program using 8085 microprocessor kit. APPARATUS REQUIRED: 8085 microprocessor kit, power supply. ALGORITHM: STEP 1: Load HL register pair with a memory pointer. STEP 2: Get the count to B register and clear accumulator. STEP 3: Push the count to stack pointer. STEP 4: Increment memory pointer. STEP 5: Add the content of memory location to accumulator. STEP 6: If carry results increment D register. STEP 7: Decrement count. If it is not zero go to STEP 4. STEP 8: Else move the sum to E register. STEP 9: Get the count from stack pointer. STEP10: Subtract the count from sum(content of DE pair). STEP11:If the subtraction results a carry add the count to the result and get the remainder STEP12: Otherwise increment B register content and go to STEP10. STEP 13: Store the quotient and remainder in successive memory location. PROGRAM: ...

Block Transfer and Sorting

3. a) SMALLEST OR LARGEST NUMBER IN AN ARRAY Aim:             To write an 8085 assembly language program that finds the smallest (or largest number in an array and execute the program using microprocessor kit. Apparatus required : 8085 Microprocessor kit, Power supply Algorithm: Smallest number in an  array Step 1:             Initialize HL register pair with a memory pointer. Step 2:             Get the count to B register and decrement the count. Step 3:             Increment the memory pointer Step 4:             Move contents of memory pointer to accumulator. Step 5:             Increment memory pointer and compare the contents with accumulator. Ste...