Showing posts with label program. Show all posts
Showing posts with label program. Show all posts

Saturday, 29 July 2017

Create static library for C program in Linux

Create static library for C program in Linux


Consider your C program has three files, which are addSub.c, mulDiv.c and main.c

addSub.c : 
int add(int x, int y)
{
    return x + y;
}
 
int sub(int x, int y)
{
        return x - y;
}
mulDiv.c : 
int mul(int x, int y)
{
    return x * y;
}
 
int div(int x, int y)
{
        return x / y;
}
main.c : 
#include <stdio.h>
 
int main(int argc, char *argv[])
{
    printf("%d ", add(10, 15));
    printf("%d ", sub(50, 15));
    printf("%d ", add(10, 3));
    printf("%d ", add(100, 4));
    return 0;
}

1 . Compile and create object file for addSub.c and mulDiv.c 
gcc -c addSub.c mulDiv.c -Wall
2.  Create static library( liboperation.a ) for compiled files 
ar -cvq libopeartion.a addSub.o mulDiv.o
3.  We can list the available files from library file using following
ar -t libopeartion.a
4. Compile the main program with linking the library 
gcc -o output main.c libopeartion.a
5. Run the created output executable file
./output 

{ Read More }


Tuesday, 18 July 2017

Create Matrix Effect in CMD BY a simple C program

Create Matrix Effect in CMD BY a simple C program


Creating Matrix Effect in CMD by a Simple C Program:




          Guys today Im providing you a simple .exe file which can create Matrix effect in CMD(Win32bit OS only).
  
So Download this .exe file from here

This is a sample for checking purpose.

And this is the source code for changing name in place of my name.

Download source code from here.

Open this .C file with TurboC Compiler and modify it and then click on compile button.

Modify only Name as in this program as I write ******Khattak******.

Now click on Compile Button and this time click on make option.It will create  *.exe file (i.e. ktk.exe).

So if you like my post then share it with friends and everyone.


{ Read More }


Saturday, 1 July 2017

Create your Basic Program by using QBasic 4 5 Full Programming language

Create your Basic Program by using QBasic 4 5 Full Programming language




QuickBASIC Program run mainly in MS-DOS 5 mode and can create a simple application in DOS environment. QB is an Integrated Development Environment (or IDE) and compiler for the BASIC programming language that was developed by Microsoft.

QuickBASIC continues to be used in some schools, usually as part of an introduction to programming, though it is fast becoming replaced by more popular compilers.It also has an unofficial community of hobby programmers who use the compiler to write games, GUIs and utilities in DOS Mode. But Nowadays, Programmers often use DOS emulators, such as DOSBox, to run QuickBASIC on Linux and on modern hardware that no longer supports the compiler

Recently, a set of TCP/IP routines for QuickBASIC v4.5 and 7.1 has revitalized some interest in the software. In particular, the vintage computer hobbyist community has been able to write software for old computers that run DOS, allowing these machines to access other computers through a LAN or the internet. This has allowed systems even as old as an 8088 to serve new functions, such as acting as a Web server or using IRC Internet Relay Chat our best example client is mIRC.

Microsofts Visual Basic was the successor of QuickBASIC. Other compilers, like PowerBASIC and FreeBASIC, have varying degrees of compatibility. QB64, a multiplatform QuickBASIC compiler, is being developed and aims to be 100% compatible according to wikipedia.

If you want to try or use this program you need to know the basics of QBasic programming. The QBasic language is made of instructions called statements. The statements must be written according to what is called "QBasic syntax rules". You can visit the Help section of QBasic for further information on how to write a proper syntax or see live samples with a basic guide on how to use this program. Here

Sample QBasic Command.
Open DOS Prompt in C: Directory, Type QBASIC and Press Enter.
Type the following 3 line statement below.

CLS
COLOR 1
PRINT "QBasic test Hello World"

Note: Make sure you have QBasic installed in your computer before do the following.

1. The CLS statement tells the computer to Clear The Screen
2. The COLOR statement tells the computer to Set a Color Attributes of Console Output
3. While PRINT statement tell the computer what text to display on the screen.

Download Qbasic_v4.5: Here

Note: You can Post your Sample Basic Program as comment for our beginners..


More Tags: Angry Bird, Blogger, Fate , Plants Vs Zombie, Special Force, Point Blank, Ai Maps, Deep Freeze UnFreezer, Ninja Saga, Deep Freeze, Samsung SGH, Guitar Pro, USB XP Install, Yahoo 443 Problem, Turtle Odyssey, GTA San-Andreas, PlayStation, Tips Tweaks Tricks, HTML, Facebook, Animated JPG, Counter-Strike, USB Windows Format, Screensaver, USB Security.
{ Read More }


Thursday, 18 May 2017

Converting a simple program in Python to MIPS Assembly Language using the MARS Emulator

Converting a simple program in Python to MIPS Assembly Language using the MARS Emulator


     
                 See how you can convert a simple python program involving a for loop into the MIPS Assembly Language using the MARS Emulator.

Read Page ----->
{ Read More }


Counting the number of times pressed of Switch C program in MPLAB X

Counting the number of times pressed of Switch C program in MPLAB X


In this program we are going to count the number of times a switch pressed,and displaying it on a LCD .. and each time the switch pressed a LED will lighted up.




First create a new project and add a c main file like in the  steps for  Blinking a LED using MPLAB X , PIC16F877A

Components 


1. PIC16F877A micro controller
2. animated LED  
3. A toggle switch
4.16x2 LCD display




Steps in the program

1. define the ports for easy usage 

Defines the control pins of LCD to the 0th,1st and 2nd pin of PORT D
    #define RS RD0
    #define RW RD1
   #define EN RD2
Defines the data port of the  LCD to PORT B
   #define DATA PORTC
Defines switch in the 0th pin of PORT C
   #define S RC0
Defines LED on the 3rd pin of PORT D
   #define L RD3
2. Function declarations .. here we declare 3 functions  and all the 3 functions is for LCD

void LCD_CMD(unsigned int value); //This function is pass the LCD commands
void LCD_DAT(unsigned int value); // this is for pass the DATA to the LCD which is to displayed 
void LCD_INIT(); //this to initialize the LCD
void delay(); // this is to delay the LCD commands 

for more refer the    Interfacing LCD with PIC16F877A in MPLAB X

3. next is main function .. in main function we make 
  •  PORT C as input where we have connected the switch
  •  PORT D as output where we have connected the LED and control pins of LCD
  • PORT B as outout where we have connected DATA pins of LCD
    TRISC  =0x0F;
    TRISD  =0x00;
    TRISB = 0x00;

4. The function LCD_INIT(); is called for initializing the LCD
5. Declared a variable called count, and initialized it to zero
   int count;
   count=0;
6.  we put the LED off 
7. now we are going for a infinite loop by 
    while(1)
    { 
     }
8. In the loop we are checking switch is ON or OFF condition
 if the switch is ON ; LED is on and count is incremented by 1 and display the value of count in LCD 

if the Switch is OFF it wait for the condition when the Switch is ON 

schematic diagram 



full Program
 ###################################################################################
    /*
 * File:   switchcount.c
 * Author: Ebin Ephrem
 
 */

#include<htc.h>
__CONFIG(0x193A);

C
#define RS RD0
#define RW RD1
#define EN RD2
#define DATA PORTB
#define S RC0
#define L RD3

void LCD_CMD(unsigned int value);
void LCD_DAT(unsigned int value);
void LCD_INIT();
void delay();



void main(void)
{
    TRISC  =0x0F;
    TRISD  =0x00;
    TRISB = 0x00;
LCD_INIT();
int count;
count=0;
L=0;

  while(1)
  {
if( S == 1)
       {
    while(S==1);
            L= ~L;
                     count = count+1;
              LCD_CMD(0x01);
        delay ();
    LCD_DAT(0 + (count % 10));
}
       }
 }

void LCD_INIT()
 {
    LCD_CMD(0x01);
    delay ();
    LCD_CMD(0x38);
    delay ();
    LCD_CMD(0x0F);
    delay ();
    LCD_CMD(0x06);
    delay ();
    LCD_CMD(0x0c);
    delay ();

    LCD_CMD(0x80);
    delay ();
}
void LCD_CMD(unsigned int  value)
{
    DATA =  value;
    RS=0;
    RW=0;
    EN=1;
    delay ();
    EN=0;
    delay ();
 }

void LCD_DAT(unsigned int value)
{
    DATA= value ;

    RS=1;
    RW=0;
    EN=1;
    delay ();
    EN=0;
    delay();

}

void delay(void)
{
    int counter = 0;
    for (counter = 0; counter<1000; counter++) {
        ;
    }
}





{ Read More }


Sunday, 9 April 2017

Create shared library for C program in Linux

Create shared library for C program in Linux


Consider you c program has two file, which are functions.c and main.c

Consider your current working directory is /home/sujin/shared/

functions.c
int add(int x, int y)
{
    return x + y;
}
 
int sub(int x, int y)
{
        return x - y;
}
 
int mul(int x, int y)
{
        return x * y;
}
 
int div(int x, int y)
{
        return x / y;
}
main.c
#include <stdio.h>
int add(int x, int y);
int sub(int x, int y);
int mul(int x, int y);
int div(int x, int y);
 
int main(int argc, char *argv[])
{
    printf("%d ", add(10, 15));
        printf("%d ", sub(50, 15));
        printf("%d ", mul(10, 3));
        printf("%d ", div(100, 4));
        return 0;
}

1. Compile library source file(functions.c) into position independent code
gcc -c -fpic functions.c -Wall
2. Create shared library from the object file generated
gcc -shared -o libfun.so functions.o 
3. Compile the main program with shared library
gcc -o output main.c -lfun
/usr/bin/ld: cannot find -lfun
collect2: ld returned 1 exit status
4. Compile with giving path of shared library
gcc -L/home/sujin/shared/ -Wall -o output main.c -lfun
5. Run the program
./output 
./output: error while loading shared libraries: libfun.so: cannot open shared object file: No such file or directory
6. Check current LD_LIBRARY_PATH. 
echo $LD_LIBRARY_PATH
7. ILD_LIBRARY_PATH is not current working directory or empty then set the LD_LIBRARY_PATHS as current working directory
LD_LIBRARY_PATH=/home/sujin/shared:$LD_LIBRARY_PATH
8. Run the program
./output 
./output: error while loading shared libraries: libfun.so: cannot open shared object file: No such file or directory
9. Export the LD_LIBRARY_PATH. In linux we need to export the changes in the environment variable
export LD_LIBRARY_PATH=/home/sujin/shared/:$LD_LIBRARY_PATH
10. Run the program
./output
25
35
30
25
{ Read More }