Search

C Programming Code Examples

Learn to C programming by examples

C is a general-purpose, procedural, imperative computer programming language developed in 1972 by Dennis M. Ritchie at the Bell Telephone Laboratories to develop the UNIX operating system. C is the most widely used computer language. It keeps fluctuating at number one scale of popularity along with Java programming language, which is also equally popular and most widely used among modern software programmers.
C Programming Code Examples


C Programming Tutorials 

* C proramming code examples:

1. Beginners Lab Assignments
2. C on Unix
3. Code Snippets
4. Data Structures
5. File Operations
6. Games and Graphics
7. Gnu-Linux
8. Hardware Interaction Through C
9. Mathematics
10. Miscellaneous
11. Small Programs
12. Sorting Searching

Ebook:
C Programming Code Examples


XML Technologies Tutorial

XML Technologies Tutorial



Extensible Markup Language (XML) is the universal format for data on the Web. XML allows developers to easily describe and deliver rich, structured data from any application in a standard, consistent way. XML does not replace HTML; rather, it is a complementary format.

XML TECHNOLOGIES

Script Programming Tutorials

CNC Programming Examples - Subprogram

Taper Threading with G32 a CNC Programming Example

* Best ebooks for CNC programming: 
CNC Programming Basics 
G-Code and M-Code 
CNC programming 
G-Code Reference 
CNC Machine Tutorial 

G32 is used for thread cutting, but with G32 we can just make a single threading cut. This all mean that you yourself have to do all the work of threading tool positioning.
For brief introduction of G32, G33 read CNC Fanuc G33 G32 Threading G Code

  • Longitudinal thread.
  • Transverse thread.
  • Tapered thread.
  • Single and Multiple Start threads with a constant pitch.
  • Variable pitch and taper angles by Chaining thread cutting blocks.
For taper threading with G32 first take the tool to the start position.
Then make the thread cut with G32 and give the values of destination point in X, Z axis along with thread pitch F.
The Z value in the G32 thread cutting has the same meaning as the Z value in the G76 cycle or the G92 threading cycle. It represents the end position.
There are multiple possibilities of taper threading on cnc lathe machines.
Taperd threading with G76 threading cycle.
Taper Threading with G92 Threading Cycle.
CNC Programming Example G92 Taper Threading Cycle.

Taper Threading with G32


Taper Threading with G32 a CNC Programming Example
N10 G50 S800 T0100
        N20 G97 S800 M03
        N30 G00 X90.0 Z5.0
        N40 X22.026
        N50 G32 X49.562 Z-71.5 F3.0
        N60 G00 X90.0
        N70 Z5.0
        N80 X21.052
        N90 G32 X48.588 Z-71.5
        N100 G00 X90.0
        N110 Z5.0
        N120 X150.0 Z150.0
        N130 M30
Here are just two passes of taper threading in this cnc programming example, but you can repeat the thread passes as much you require.

CNC Programming Examples - Peck Drilling Lathe

Fanuc G83 Peck Drilling Cycle

G83 peck drilling cycle perform the drilling operation in multiple pecks, this technique makes deep-hole drilling easy and economical.


* Best ebooks for CNC programming: 
CNC Programming Basics 
G-Code and M-Code 
CNC programming 
G-Code Reference 
CNC Machine Tutorial 

Cutting feed is performed intermittently to the bottom of the hole while chips are discharged.
As the drilling is performed to the bottom of the hole with feed in multiple small steps, every time a specified depth is made and then drill retracts, then drill makes the next peck, this operation is repeated again and again until the drill depth is reached.

Contents
  • Syntax
  • Usage
  • Working
  • G98 G99 Modes
    • Example
  • Repeat Drilling
  • Working Example

Syntax

G83 X... Y... Z... R... Q... F... K...
Parameter Description
X Hole position in x-axis.
Y Hole position in y-axis.
Z Depth, tool will travel with feed to Z-depth starting from R plane.
R Position of the R plane.
Q Depth of cut for each cutting feed (Peck).
K Number of cycle repetitions (if required) .
F Feedrate.
Once given in program G83 peck drilling cycle is repeated at every axis movement until G80 is given in program to end peck drilling cycle.

Usage

N150 M06 T02
        N160 G90 G00 X60 Y28 Z12 S750 M03
        N170 G99 G83 X60 Y28 Z-17 Q6 R2 F60
        N180 G98 Y12
        N190 G91 G80 G28 X0 Y0 Z0 M05
        N200 M30
In the above example code first drill is done at X60 Y28 and second at Y12 and then peck drilling is cycle is ended with G80.
6mm pecks are taken to complete total drilling depth of 17mm.

Working

Here is briefly described how G83 peck drilling cycle works,
1- Rapid traverse to X, Y drilling position.
2- Rapid traverse to R-plane.
3- Drilling with feed Q deep.
4- Retraction with Rapid traverse to R-plane.
5- Rapid traverse to Q-d deep (d value is specified in parameters).
6- Drilling with feed Q+d deep.
7- Retraction with Rapid traverse to R-plane
– this whole procedure is repeated until drill reaches Z-depth position,
– then drill is retracted to R-plane or Initial-level depends on G99 or G98 which one is given in program.

G83 peck drilling cycle working

G98 G99 Modes

After completing drilling depth the return is made with Rapid feed, the return height can be controlled through using G98 or G99.
G98 Drill will return to the Initial level
G99 Drill will return to R-plane.
G98, G99 can be used multiple times during G83 peck drilling cycle.

Example

N30 G83 X10 Y30 Z-17 Q5 R2 F75
        N40 Y10
        N50 G98 X30
        N60 G99 Y30
        N70 X90
        N80 Y10
        N90 G80

Repeat Drilling

G83 peck drilling cycle, drilling operation can be repeated multiple times. The drilling is repeated K times if K value is given with G83.
Repeat drilling is normally used with G91 Incremental mode, and a good example of repeated drilling is Grid-plate drilling. For working example see G81 drilling cycle.

Working Example


G83 Peck drilling cycle Example
N10 M06 T1
        N20 G90 G00 X12.5 Y10 Z12 S1000 M03
        N30 G99 G83 X12.5 Y10 Z-17 R2 Q4 F75
        N40 Y30
        N50 G98 X57.5
        N60 G99 Y10
        N70 G91 G80 G28 X0 Y0 Z0 M05
        N80 M30


------------

G83 Peck Drilling Cycle Example

CNC programming example code for the G83 Peck Drilling Cycle. G83 deep hole peck drilling cycle makes the drilling of deep holes a breeze.
As with G81 drilling cycle you can do simple drilling in a fast and easy way.
But G83 peck drilling due to its specialty of pecking throws away the chips after every cut or peck and this way also the coolant reaches to the bottom of the hole in a free way, so keeps the drill and component cool and clean.
The following G83 peck drilling cycle example code illustrates the use of peck drilling cycle in an easy to understand way, even the beginner level cnc programmers/cnc machinists will understand the working with ease.
For a complete working of G83 Peck Drilling Cycle read
  • G83 Peck Drilling Cycle (Deep Hole) for Fanuc
  • G83 Peck Drilling Cycle (Deep Hole) for Haas CNC

G83 Peck Drilling Cycle Example Program


G83 Peck Drilling Cycle Example
N1 T1 M06
            N2 G90 G54 G00 X.3 Y.3
            N3 S1200 M03
            N4 G43 H01 Z1. M08
            N5 G83 Z-1.5 Q.5 R.1 F10.
            N6 X1.2 Y1.2
            N7 G80 G00 Z1. M09
            N8 G91 G28 Z0. M05
            N9 M30
------------

G81 Drilling Cycle G83 Peck Drilling with G98 G99 Example Program

A complete cnc part-program which shows how G98 and G99 (canned cycle return level) work with G81 drilling cycle and G83 peck drilling cycle for drilling of a component which have different heights.
Contents
  • G98 G99 Summary
  • CNC Part Program
  • Explanation
  • G & M Codes

G98 G99 Summary

G98 and G99 are modal commands that change the way canned cycles (G81,G83 etc.) operate.
When G98 is active, the Z-axis will return to the start position (initial plane) when it completes an single operation.
When G99 is active, the Z-axis will be returned to the R point (plane) when the canned cycle completes a single hole. Then the machine will go to the next hole.

G81 drilling cycle working – G98 G99 return level

CNC Part Program


G81 Drilling Cycle with G98 G99 G code Example Program
N10 M06 T01
                N20 G90 G00 X10 Y30 Z12 S1000 M03
                N30 G99 G81 X10 Y30 Z-17 R2 F75 (Hole 1)
                N40 Y10                         (Hole 2)
                N50 X30                         (Hole 3)
                N60 Y30                         (Hole 4)
                N70 G98 X90                     (Hole 5)
                N80 G99 Y10                     (Hole 6)
                N90 X110                        (Hole 7)
                N100 G98 Y30                     (Hole 8)
                N110 G91 G80 G28 X0 Y0 Z0 M05
                N120 M06 T02
                N130 G90 G00 X60 Y28 Z12 S750 M03
                N140 G99 G83 X60 Y28 Z-17 Q6 R2 F60  (Hole 9)
                N150 G98 Y12                         (Hole 10)
                N160 G91 G80 G28 X0 Y0 Z0 M05
                N170 M30

Explanation

N10- Tool change (M06) to tool no.1
N20- Rapid traverse to X10 Y30 Z12, Spindle started clockwise (M03) with 1000rpm (S1000).
N30- Drilling starts (G81) at X10 Y30 with cutting-feed (F75) drill will retract to R-plane after drilling operation.
N40- Next drilling position Y10 (as G99 is a modal g-code drill will keep on retracting to R-plane until G98 is given).
N50- Next drill at X30.
N60- Drill at Y30
N70- Drill at X90 & Retract to Initial-plane.
N80- Drill at Y10 & Retract to R-plane.
N90- Drill at X110
N100- Drill at Y30 & Retract to Initial-plane.
N110-  Drilling cycle is cancelled (G80), return to reference point (G28) for tool change, stop spindle (M05).
N120- Tool change (M06) to tool number 2.
N130- Rapid traverse to X60 Y28 Z12, start spindle at 750rpm (S750) clockwise (M03).
N140- G83 Peck drilling starts at X60 Y28, drill depth is Z-17 and drill peck size is Q6, drilling feed is F60
N150- Next deep drill at Y12 (return to initial point).
N160- G83 Peck drilling cycle cancelled with G80, tool returned to reference point (G28), spindle stopped (M05).
N170- Part-program end with return to program start (M30)

G & M Codes

Code Description
T Tool no. used.
M06 Tool change command.
G90 Absolute programming
G00 Rapid traverse
S Cutter speed
M03 Cutter rotation Clockwise
M08 Coolant on.
G81 Fanuc drilling cycle.
G83 Fanuc peck drilling cycle.
G98 Return to initial point in canned cycle.
G99 Return to R point in canned cycle.
F Cutting feed.
G80 Canned cycle cancel.
M09 Coolant off.
G28 Return to reference position.
G91 Incremental programming.
M05 Cutter rotation stop.
M30 CNC part-program end with return to program-start.

Logo programming language ebook

Logo programming language


Logo is a programming language that is easy to learn. It is used for teaching students and children how to program a computer. It was developed to process a list of words. A command is an instruction, which the computer can understand and execute. In principle, the computer only understands very basic commands, which can then be combined to form more complicated instructions. Such a sequence of commands is called a computer program. Writing computer programs is not easy. There are programs which has millions of commands. To keep track of such a complicated program, it is very important to approach the task of writing a program in a structured and well-thought-out manner. This is what we will learn in this Logo programming course.

Click here to order ebook NOW!

Assembly Code Examples

Assembly Code Examples

Assembly language is a low-level programming language for a computer or other programmable device specific to a particular computer architecture in contrast to most high-level programming languages, which are generally portable across multiple systems. Assembly language is converted into executable machine code by a utility program referred to as an assembler like NASM, MASM, etc.
Assembly Code Examples
Assembly Code Examples






* Assembly Code Examples:
  1. A small program that calculates and prints terms of the Fibonacci series
  2. Alarm
  3. An implementation of SLIP (Serial Link IP), RFC 1055 in assembly language
  4. Assembly language program which shows the current date
  5. This program provides BASIC programs with access to the program loader (LOAD)
  6. This program is used to set the PSP address for a compiled BASIC program
  7. BIOS-based disk I-O to access MS-DOS file structure
  8. Boot loader for a roll-your-own operating system
  9. Control-Break handler for Lattice C programs
  10. Break
  11. Break Handling Utilities Module
  12. Burnout
  13. Calculator
  14. Cd Check
  15. Char
  16. MSDOS 2.00 Function Library for Lattice C
  17. Checks the validity of an ISBN by verifying the checksum
  18. Chips
  19. Circle
  20. This is a simple litte assembler program that cleans out
  21. This program removes all control codes except for line feeds
  22. A DOS 2.0 filter for word processing document files
  23. CLEAR Utility to clear display and set character attributes
  24. Clock
  25. Subroutine called by a basic program to scroll a window
  26. This program provides COBOL programs with access to the program loader (LOAD)
  27. Colours routine
  28. Serial communications port interupt intercepter AHA 8502.27
  29. Command line program allows piping of output from other programs
  30. Program to prevent CTRL+ALT+DEL from restarting the system
  31. Demo showing how to use 'flat real mode'
  32. Report installed device drivers
  33. Disables the cache on a 486 and Pentium processor
  34. A listing into pages and give new subtitles
  35. Drives
  36. Drives Exist
  37. Disk Watch
  38. Ejects a SCSI tape (or CD-ROM) from a drive
  39. EXECSUB - execute program from compiled BASIC - requires DOS 2.00
  40. Fetches and prints the network serial number under Novell Netware 3.11
  41. A utility to report free space on the default or selected disk drive
  42. Get disk free space function
  43. FXN4BH --- demonstrate use of the PC-DOS 2.0 EXEC function call 4BH
  44. Game Port
  45. Gets a list of Queue servers under Novell Netware 3.11
  46. Absolute Disk Read
  47. Get current Segment Values
  48. Get Space
  49. Device Driver Header
  50. Inthand
  51. Issues the CPUID instruction to fetch the family, model and stepping ID
  52. Multi-function fractal demonstration program which results in 255 byte program
  53. Determines the type of UART in each serial port
  54. Sets up 'flat real mode'
  55. Show Memory
  56. Shows a demonstration of a routine which scrolls a window on a text mode screen
  57. Shows one possible method for checking the type of video card
  58. This is a small sound example for the IBM PC
  59. Tests for the well documented Pentium divide bug
  60. The venerable IBM-370 had a numeric format called packed decimal



C# programming Examples

Learn C# Programming by examples. 
Guide to C# programming. 


C# programming Examples
C# programming Examples

CSharp Examples:

1. A hierarchy of timelines
2. A rectangle with curved corners
3. About Dialog
4. Add a control to a Panel
5. Add buttons to a Canvas with code
6. Add child control
7. Add control to a form window
8. Add control to a window
9. Add Ellipse, TextBlock to a Tree
10. Add image to Button
11. Add Image to Statusbar
12. Add items to combo box
13. Add Polyline to UniformGrid
14. Add Separator to StackPanel
15. Add Thickness for Padding
16. Adding Hyperlink to TextBlock
17. All Mouse Cursors
18. An ellipse that has been scaled by 20%
19. Anchor Two Buttons
20. Animate EndPoint
21. Animate the background color
22. Animation In Style
23. Application Exit event
24. Application Startup event
25. Application.GetResourceStream
26. Apply Syntax Highlighting in a Text Control
27. Automatic Width and Height
28. AutoScroll Window
29. Basic DialogBox
30. Bind a TabControl to a data source
31. Bind current time to Button
32. Bind to XML Data embed the data directly
33. Binding Label to TextBox
34. Binding With Data Context
35. Bold text in Flow document
36. BorderLess Window
37. Bouncing Ball
38. Built-In Command Bindings
39. Button Click event handler
40. Button Image, Size, Parent
41. Capture Mouse Ellipse
42. Cast event sender to a control
43. Center form window
44. Change Button text
45. Change StackPanel Orientation
46. Check Spelling Error