C++ Program for Digital Clock

#include
#include
#include
#include
#include
void main()
{
int i=23,j=58,k,l,a=2;
mat:
for(;;i++)
{for(;j<60;j++)
{for(k=0;k<60;k++)
{
l=1;
//settextstyle(triplex_font,horiz dir,a)
printf("%d:%d:%d",i,j,k);
printf("\nif u want to exit press Q");
sleep(l);
clrscr();
if(i==23&&j==59&&k==59)
{
i=0;j=0;k=0;
goto mat;
}
}}}
max:
getch();
}



C Program for Universal Calendar

#include
#include
#include
#include
#include
#include
#include

#define std_year 1000
#define std_month 1
#define std_date 1


void calender(void);
long yearlydiff(long year);
void anaclock(void);
void presentation(void);
void digiclock(void);
void menu(void);


void main()
{
char ch;
/********************* auto detect the driver *********************/
int gdriver,gmode;
gdriver=DETECT;
initgraph(&gdriver,&gmode,"c:\tc3\BGI");

/***************** clearing all staying on the screen
****************/
cleardevice();
presentation();
for(;;)
{
menu();
ch=getch();
if(ch=='1') calender();
else if(ch=='2') anaclock();
else if(ch=='3') digiclock();
else if(ch=='4') break;
}

}

void calender(void)
{
char year_str[10],month_str[6],t[2],date_str[3], temp[10];
int year,month,i,flag,start,j,lessx,lessy,k,l;
long days=0;
int months[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
char
*monthname[13]={"","JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE",
"JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER"};
char *dayname[8]={"","SAT","SUN","MON","TUE","WED","THU","FRI"};

int
position[35][2]=/*{{257,210},{314,210},{371,210},{428,210},{485,210},
{542,210},{600,210},{257,270},{314,270},{371,270},
{428,270},{485,270},{542,270},{600,270},{257,330},
{314,330},{371,330},{428,330},{485,330},{542,330},
{600,330},{257,390},{314,390},{371,390},{428,390},
{485,390},{542,390},{600,390},{257,450},{314,450},
{371,450},{428,450},{485,450},{542,450},{600,450} }; */


{{187,180},{244,180},{301,180},{358,180},{415,180},{472,180},{530,180},{18
7,240},
{244,240},{301,240},{358,240},{415,240},{472,240},{530,240},{187,300},{244
,300},
{301,300},{358,300},{415,300},{472,300},{530,300},{187,360},{244,360},{301
,360},
{358,360},{415,360},{472,360},{530,360},{187,420},{244,420},{301,420},{358
,420},
{415,420},{472,420},{530,420}};

int dayposition[7][2]={{257,150},{314,150},{371,150},{428,150},
{485,150},{542,150},{600,150} };

/************* clearing all thing staying on the screen
***************/
cleardevice();

/************************ year input ******************************/
for(k=1;k<640;k+=4)
for(l=1;l<479;l+=4)
putpixel(k,l,DARKGRAY);

setcolor(LIGHTBLUE);
settextstyle(8,HORIZ_DIR,4);
outtextxy(50,50,"Enter the year and press enter");
outtextxy(90,80,"(between 1000 & 10000)");
for(i=0;;i++)
{
year_str[i]=getch();
if(year_str[i]=='
')
{
year_str[i]='}

C Program to delete Existing File

#include
#include
int delete_file(char far *filename)
{
union REGS regs; struct SREGS sregs;
int ret;
regs.h.ah = 0x41;
regs.x.dx = FP_OFF(filename);
sregs.ds = FP_SEG(filename);
ret = intdosx(&regs, &regs, &sregs);


return(regs.x.cflag ? ret : 0);
}

main(void)
{
int err;
char fname[20];
clrscr();
printf("ENTER THE THE MOST FILE U WANT TO DELETE ::: ");
gets(fname);
err=delete_file(fname);
if(!err)
printf("FILE DELETED");
else
printf("NOT ABLE TO DELETE ");
getch();
return(0);
}


access memory

/*-------------DUMP MEMORY-------------
* Moi doan bo nho (memory segment) la mot khoi gom 64KB = 2^16 byte o nho
* lien tiep. Moi o nho duoc xac dinh bang mot dia chi doan va mot offset
* viet duoi dang [segment : offset]
*
* Chuc nang chuong trinh dump memory la truy cap mot doan bo nho
* mdump [segment] [offsetstart] [offsetend]
*
* FP_OFF gets a far address offset
* FP_SEG gets a far address segment
* MK_FP makes a far pointer
*
* Declaration:
* unsigned FP_OFF(void far *p);
* unsigned FP_SEG(void far *p);
* void far *MK_FP(unsigned seg, unsigned ofs);
*
* Example (for all three macros):
*
* #include
* #include
*
* main()
*{
* char *str = "Hello\n";
*
* printf("The address pointed to by str is %04X:%04X\n",
* FP_SEG(str), FP_OFF(str));
* printf("The address of str is %04X:%04X\n", FP_SEG(&str), FP_OFF(&str));
* return 0;
**/
#include
#include

int mdump(unsigned int seg, unsigned int offstart, unsigned int offend, int flag);
unsigned int getaddress(char *p);
int pause();

#define LINES_PER_PAGE 16
char *errmess[]= {
"\n\nUsage: %s segment [start] [end] [p]\n",
"\n\n %s is not a number!\n",
};

int main(int argc, char *argv[]){
int pflag= 0;
unsigned int offstart= 0, offend= 0xFFFF, seg, temp;

switch (argc){
case 5:
if (argv[4][0]=='P'||argv[4][0]=='p')
pflag= 1;
else{
printf(errmess[0],argv[0]);
exit(1);
}
case 4:
if (argv[3][0]=='P'||argv[3][0]=='p')
pflag= 1;
else
offend= getaddress(argv[3]);
case 3:
if (argv[2][0]=='P'||argv[2][0]=='p') {
pflag= 1;
offend= 0xFFFF;
}else
offstart= getaddress(argv[2]);
case 2:
seg = getaddress(argv[1]);
break;
default:
printf(errmess[0],argv[0]);
exit(0);
}
if(offstart>offend){
printf("Start offset must less than End offset");
exit(0);
}
mdump(seg, offstart, offend, pflag);
return 0;
}
unsigned int getaddress(char *p){
char *q;
unsigned int retval= 0;
q= p;
while(*q){
if((*q >= 'a')&&(*q <= 'f'))
retval= retval*16 + *q - 'a' + 10;
else if((*q >= 'A')&&(*q <= 'F'))
retval= retval*16 + *q - 'A' + 10;
else if((*q >= '0')&&(*q <= '9'))
retval= retval*16 + *q - '0';
else{
printf(errmess[1],p);
exit(1);
}
q++;
}
return retval;
}

int mdump(unsigned int seg, unsigned int offstart, unsigned int offend, int flag){
unsigned char far *p;
int ci;
char str[17];
p= MK_FP(seg, offstart);
while( offstart<=offend) {
if( flag) pause();
printf("%04X:%04X ",FP_SEG(p), FP_OFF(p)); //din chi dau cua line
for( ci= 0; ci<>
if(++offstart==0xffff){
printf(" %s\n", str);
exit(0);
}
printf("%02X ",*p);
if (ci== 7) printf(" ");
str[ci]= ((*p>=32)&&(*p<=126))? *p: '.';
if(ci==15) printf(" ");
}
str[ ci]= 0;
printf(" %s\n", str);

}
return 0;
}
int pause() {
static int cj= 0;
if( cj== LINES_PER_PAGE) {
cj= 0;
getch();
printf( "\n");
} else
cj++;
return 0;
}

Result for Acess Memory:

CCP Capture PWM with PIC Microcontroller
//**************************************
//
// Name: CCP Capture PWM with PIC Microc
// ontroller
// Description:Capture Function for PIC
// Microcontroller.
// By: SouthOfHeaven
//
//This code is copyrighted and has// limited warranties.Please see http://
// www.Planet-Source-Code.com/vb/scripts/Sh
// owCode.asp?txtCodeId=7419&lngWId=3//for details.//**************************************
//

; Use 10 MHz crystal frequency.
;;;;;; Assembler directives ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
list P=PIC18F452, F=INHX32, C=160, N=0, ST=OFF, MM=OFF, R=DEC, X=ON
#include P18F452.inc
__CONFIG _CONFIG1H, _HS_OSC_1H ;HS oscillator
__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L & _BORV_42_2L ;Reset
__CONFIG _CONFIG2H, _WDT_OFF_2H ;Watchdog timer disabled
__CONFIG _CONFIG3H, _CCP2MX_ON_3H ;CCP2 to RC1 (rather than to RB3)
__CONFIG _CONFIG4L, _LVP_OFF_4L ;RB5 enabled for I/O
;;;;;;; Variables ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
cblock 0x000;Beginning of Access RAM
endc
;;;;;;; Macro definitions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
MOVLFmacro literal,dest
movlw literal
movwf dest
endm
;;;;;;; Vectors ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
org 0x0000 ;Reset vector
nop
goto Mainline
org 0x0008
goto $

org 0x0018
goto $
;;;;;;; Mainline program ;;
Mainline

INITIAL
MOVLF 0x00, T3CON ; Set up CCP2 for use with timer1
MOVLF 0x00, INTCON;
MOVLF0x00, PIE1;
MOVLF 0x00, PIR1;
MOVLF B'00000010', TRISC ;Set up IO on PORTC for PWM
MOVLF B'00000101',T2CON ;Timer 2 on and prescale of 4
MOVLF D'124', PR2 ; PR2 T2
MOVLF 0x01, T1CON ;TMR1 ON
MOVLF B'01100100', CCPR1L ;DUTY CYCLE
MOVLF B'00001111', CCP1CON;PWM MODE
MOVLF 0x00, CCPR2L ;
MOVLF 0x00, CCPR2H ;
MOVLF B'00000101', CCP2CON; Initially check for rising



POLL btfsc PIR2,CCP2IF
rcall Capture
goto POLL

Capture
btg CCP2CON,CCP2M0; Toggle between Rising/Falling
bcf PIR2,CCP2IF; Reset int Flag
return
end

Blinkalive Subroutine for PIC microcontroller

//**************************************
//
// Name: Blinkalive Subroutine for PIC m
// icrocontroller
// Description:BLinkalive Subroutine for
// PIC microcontroller. This subroutine bri
// efly blinks the LED next to the PIC ever
// y two-and-a-half
; seconds.
// By: SouthOfHeaven
//
//This code is copyrighted and has// limited warranties.Please see http://
// www.Planet-Source-Code.com/vb/scripts/Sh
// owCode.asp?txtCodeId=7418&lngWId=3//for details.//**************************************
//

;;;;;;; P1 for QwikFlash board ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Use 10 MHz crystal frequency.
; Use Timer0 for fifty(50) millisecond looptime.
; Blink "Alive" LED every 0.5 seconds.
; Toggle C2 output every ten milliseconds for measuring looptime precisely.
;
;;;;;;; Program hierarchy ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Mainline
;Initial
;BlinkAlive
;LoopTime
;
;;;;;;; Assembler directives ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
list P=PIC18F452, F=INHX32, C=160, N=0, ST=OFF, MM=OFF, R=DEC, X=ON
#include P18F452.inc
__CONFIG _CONFIG1H, _HS_OSC_1H ;HS oscillator
__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L & _BORV_42_2L ;Reset
__CONFIG _CONFIG2H, _WDT_OFF_2H ;Watchdog timer disabled
__CONFIG _CONFIG3H, _CCP2MX_ON_3H ;CCP2 to RC1 (rather than to RB3)
__CONFIG _CONFIG4L, _LVP_OFF_4L ;RB5 enabled for I/O
;;;;;;; Variables ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
cblock 0x000;Beginning of Access RAM
TMR0LCOPY;Copy of sixteen-bit Timer0 used by LoopTime
TMR0HCOPY
INTCONCOPY ;Copy of INTCON for LoopTime subroutine
ALIVECNT;Counter for blinking "Alive" LED
endc
;;;;;;; Macro definitions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
MOVLFmacro literal,dest
movlw literal
movwf dest
endm
;;;;;;; Vectors ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
org 0x0000 ;Reset vector
nop
goto Mainline
org 0x0008 ;High priority interrupt vector
goto $ ;Trap
org 0x0018 ;Low priority interrupt vector
goto $ ;Trap
;;;;;;; Mainline program ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Mainline
rcall Initial ;Initialize everything
Loop
btg PORTC,RC2 ;Toggle pin, to support measuring loop time
rcall BlinkAlive;Blink "Alive" LED
rcall LoopTime ;Make looptime be ten milliseconds
bra Loop
;;;;;;; Initial subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; this subroutine performs all initializations of variables and registers.
Initial
MOVLF B'10001110',ADCON1 ;Enable PORTA & PORTE digital I/O pins
MOVLF B'11100001',TRISA ;Set I/O for PORTA
MOVLF B'11011100',TRISB ;Set I/O for PORTB
MOVLF B'11010000',TRISC ;Set I/0 for PORTC
MOVLF B'00001111',TRISD ;Set I/O for PORTD
MOVLF B'00000000',TRISE ;Set I/O for PORTE
MOVLF B'10000000',T0CON ;Set up Timer0 for a looptime of 10 ms
MOVLF B'00010000',PORTA ;Turn off all four LEDs driven from PORTA
return
;;;;;;; LoopTime subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; this subroutine waits for Timer0 to complete its ten millisecond count
; sequence. It does so by waiting for sixteen-bit Timer0 to roll over. To obtain
; a period of precisely 10000/0.4 = 25000 clock periods, it needs to remove
; 65536-25000 or 40536 counts from the sixteen-bit count sequence. The
; algorithm below first copies Timer0 to RAM, adds "Bignum" to the copy ,and
; then writes the result back to Timer0. It actually needs to add somewhat more
; counts to Timer0 than 40536. The extra number of 12+2 counts added into
; "Bignum" makes the precise correction.
Bignum equ 131072-125000+12+2
LoopTime
btfss INTCON,TMR0IF;Wait until 50 milliseconds are up
bra LoopTime
movff INTCON,INTCONCOPY ;Disable all interrupts to CPU
bcf INTCON,GIEH
movff TMR0L,TMR0LCOPY ;Read 16-bit counter at this moment
movff TMR0H,TMR0HCOPY
movlw low Bignum
addwf TMR0LCOPY,F
movlw high Bignum
addwfc TMR0HCOPY,F
movff TMR0HCOPY,TMR0H
movff TMR0LCOPY,TMR0L ;Write 16-bit counter at this moment
movf INTCONCOPY,W ;Restore GIEH interrupt enable bit
andlw B'10000000'
iorwf INTCON,F
bcf INTCON,TMR0IF ;Clear Timer0 flag
return
;;;;;;; BlinkAlive subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; this subroutine briefly blinks the LED next to the PIC every two-and-a-half
; seconds.
BlinkAlive
bsf PORTA,RA4 ;Turn off LED
decf ALIVECNT,F;Decrement loop counter and return if not zero
bnz BAend
MOVLF 10,ALIVECNT ;Reinitialize BLNKCNT
bcf PORTA,RA4 ;Turn on LED for 50 milliseconds every 0.5 sec
BAend
return
end

No posts.
No posts.