Position:Electronics Blog Microchip PIC Circuits Projects Examples of CCS C Microchip PIC Series Simple Applications

Examples of CCS C Microchip PIC Series Simple Applications

Microchip PIC Serisi CCS C Örnekleri Basit Uygulamalar

Almost all of the applications made with PIC16F648 2 isis with one PIC16F628 PIC Simulation files are C and HEX code for those who are trying to learn C and a good source of the program or the circuits have a wide variety of the CCS C Compiler Used rs232, keypad, lcd,display, eeprom, counter, The conduct of VB. A lot of simple circuits based on the sample files

Below are a few examples and a list of available ugulamalardan

Extinguish Led closely with PIC16F628
PIC16F628 Led yak söndür

////////////////////////////////////////////////////////////////////////////////////
//							VsZeNeR'04		
//						   14/August/05
//						vszener@gmail.com
//	Program:	Blink of an LED every 0.5s 
//	Version:	0.0 Reviews 16F648a
//
//	Device: 16F628A PIC Compiler:	 CCS vs3.227
//	IDE: MPLAB IDE v7.20 Simulador:	 Proteus 6.7sp3
//
//	Notes: Blink of an LED every 0.5s for port B pin RB0
//////////////////////////////////////////////////////////////////////////////////

#include <16f628a.h>				//little of use
,NOWDT,NOPROTECT,PUT / / orders for the programmer
 (clock=4000000)			//Fosc=4Mhz
#use fast_io(b)

///PROGRAM
(void)
{
	set_tris_b(0xFE);				//portb as salida(RB0, the other disabled)
	disable_interrupts(GLOBAL);		//all interrupts disabled

{	
		output_low(PIN_B0);			//led off
		delay_ms(500);				
		output_high(PIN_B0);		//led on
		delay_ms(500);
	}while(TRUE);					//infinite loop
}

PIC16F648A Kayan Ledler
PIC16F648A Kayan Ledler

////////////////////////////////////////////////////////////////////////////////////
//							VsZeNeR'04		
//						   14/August/05
//						vszener@gmail.com
//	Program:	Fantastic car
//	Version:	2.0
//
//	Device: 16F648A PIC Compiler:	 CCS vs3.227
//	IDE: MPLAB IDE v7.20 Simulador:	 Proteus 6.7sp3
//
//	Notes: Sweeping lighting LED's simulating the fantastic car
//		   Port B. Adaptation of the code in basic for lordlafebre 
//
//				RB0 -> 1 º Led
//				RB1 -> 2 º Led
//				RB2 -> 3 º Led
//				RB3 -> 4 º Led
//				RB4 -> 5 º Led
//				RB5 -> 6 º Led
//				RB6 -> 7 º Led
//				RB7 -> 8 º Led
//		   Cont in the variable values ​​be stored 1-2-4-8-16-32-64-128
//		   which in binary corresponds to the sequence 00000001-00000010-00000100...
//		   are the led's to illuminate, coinciding with the lighting sequence
//		   the fantastic coche(Ecuadorian version: fantastic car)
//////////////////////////////////////////////////////////////////////////////////

#include <16f648a.h>				//little of use
,NOWDT,NOPROTECT,PUT,NOLVP / / orders for the programmer
 (clock=4000000)			//Fosc = 4Mhz
(B)					//Port B as Output

(void)
{
	int i,account;						//variables defined
(0x00);				//portb as salida
(GLOBAL);		//all interrupts disabled

{								//loop ...
		Account = 1;						//boot ...
		
		for(i=1;i<8;i++){			//led's on derecha
			output_b(cont);			//ilumino led correspondiente
			delay_ms(100);
			cont=cont*2;
			}
		
		for(i=1;i<8;i++){
			output_b(cont);			//ilumino led correspondiente
			delay_ms(100);
			cont=cont/2;
			}
			
		}while(TRUE);				//...infinito
}

Display Led bar with PIC16F648A App
PIC16F648A Led bar Display Uygulaması

////////////////////////////////////////////////////////////////////////////////////
//							VsZeNeR'05		
//						  8/Noviembre/05
//						vszener@gmail.com
//	Program:	Led's & display 7seg andodo Comm
//	Version:	0.0
//
//	Device: 16F648A PIC Compiler:	 CCS vs3.236
//	IDE: MPLAB IDE v7.22 Simulador:	 Proteus 6.7sp3
//
//	Notes: This program shows how to incorporate in our program ASM code in C.
//		   The handle asm modules in peripheral lso(One is a bar of LED's, is
//		   light up 4 LED's in a row and back again, and the other
//		   manages a bcd up counter of 0A9 and back again). Using the 
//		   peripheral decoder 4555 the bcd-7seg 74247.
//		   Connections:		A0 -> A 4555 DEC		      
//							A1 -> B 4555 DEC			
//							B4 -> A 74247/Led D1		
//							B5 -> B 74247/Led D2		  
//							B6 -> C 74247/Led D3            
//							B7 -> D 74247/Led D4	
//////////////////////////////////////////////////////////////////////////////////

#include <16f648a.h>					//little of use
,NOWDT,NOPROTECT,PUT,NOLVP / / orders for the programmer
 (clock=4000000)				//Fosc=4Mhz
#use fast_io(a)
#use fast_io(b)
#byte PORTB = 0x06 / / PORTB definitions
(void)
{
	char cont = 0;			//definition of ...
	signed char bcd=-1;		//...variables

 (0x00);		//door salida
 (0x00);		//Output portb

(;;){	//loop ...	
		output_a(account);		//corresponding LED lights

	1			;in <- 1
		addwf	bcd,1		;bcd <- w + bcd
		movf	bcd,0		;w bcd
		sublw	10			;10- w
		btfsc	status,2	;¿se ha llegado a 9?
		goto	igual		;si->ve the same
,0		;NO: in <- parte alta bcd
		goto	muestra		;ve a muestra
igual:	
		movlw	0			;w <- 0
		movwf	bcd			;bcd w
muestra:
		movwf	portb		;portb w
		#endasm					>7seg
		
		delay_ms(450);
		
		#asm / / asm module to handle leds	1			;in <- 1
		addwf	cont,1		;cont <- w + cont
		#endasm	>3)			//Have you shown the last LED?
			Account = 0;			//SI-> reset cont
		}		//...infinite
}

PIC16F648A 7 segment bcd App
PIC16F648A 7 segment bcd Uygulaması

////////////////////////////////////////////////////////////////////////////////////
//							VsZeNeR'05		
//						   22/August/05
//							vszener@gmail.com
//	Program:	Counter 0-9 display BDC & Button
//	Version:	0.0
//
//	Device: 16F648A PIC Compiler:	 CCS vs3.227
//	IDE: MPLAB IDE v7.20 Simulador:	 Proteus 6.7sp3
//
//	Notes: Counter 0 to the 9 each time you press the button and start again. Have
//		   note that you have to put the directive NOLVP for the pin B4 is of 
//		   output. When we add a button to our circuit must be taken into account
//		   This device generates 'rebounds' that must be removed to
//		   proper display on the display of the selected digit. This time
//		   eliminating "the boards' Volt performed using software. 
//		   When the A0 pin holder entering a '0 'logic(low), is 
//		   increments a digit in the display BCD.
//
//	Connections:		A0 -> boton		      
//					B0 -> a 
//					B1 -> b 
//					B2 -> c 
//					B3 -> d 
//	BCD:
//				d c b a   NUM
//				0 0 0 0    0
//				0 0 0 1    1
//				0 0 1 0    2
//				0 0 1 1    3
//				0 1 0 0    4
//				0 1 0 1    5
//				0 1 1 0    6
//				0 1 1 1    7
//				1 0 0 0    8
//				1 0 0 1    9
//////////////////////////////////////////////////////////////////////////////////

#include <16f648a.h>				//little of use
,NOWDT,NOPROTECT,PUT,NOLVP / / orders for the programmer
 (clock=4000000)			//Matt = 4MHz
(b_outputs=PIN_B0,PIN_B1,PIN_B2,PIN_B3)
#use standard_io(A)
		
///PROGRAM
(void)
{
	char i=0;	//BCD counter to table
[10]={0b0000,0b0001,0b0010,0b0011,0b0100,0b0101,0b0110,0b0111,0b1000,0b1001};	//BCD 0-9
		
	set_tris_a(0xFF);				//port as input
(GLOBAL);		//all interrupts disabled

(tabBCD[i]);			//displayBCD initializes digit 0

	for(;;){						//loop ...
		if(!input(PIN_A0))			//Have you pressed the button?
			{
				delay_ms(151);		//SI -> delay to avoid rebounds
;				//increment index counter tabBCD
(i>9)				//Digit shown? 9?
					i=0;			//YES -> restores valor index(to display digit 0)
				output_b(tabBCD[i]); //portb sample digit 7 segments
			}			
		}							//...infinite
}

Error Int PIC16F648A PORTB
PIC16F648A Error Int portB

////////////////////////////////////////////////////////////////////////////////////
//							VsZeNeR'06		
//						   01/JULY/06
//
//	Program:	Interruption Test because portb state change <4:7>
//	Version:	0.0
//
//	Device: 16F648A PIC Compiler:	 CCS vs3.249
//	IDE: MPLAB IDE v7.40 Simulador:	 Proteus 6.9sp4
//
//	Notes: This program takes care to see if the compiler does not disable the CCS house
//		   correct port b interrupt, for it must:
//		   		1. Read port B port
//		  		2. Clear bit of interruption(bit RBIF)
//		   Whenever there is a change of state in the B port pins <4:7>
//		   it will cause an interrupt, which increases a variable that is used
//		   in the main program to show the illumination of LED's. Apart, 
//		   each time there is an interruption to light up an LED connected to pin
//		   A4 Volt turned off when we get out of this interruption.
//
//		   Connections:		A0 -> A dec 4028		      
//							A1 -> B dec 4028
//							A2 -> C dec 4028
//							A3 -> D dec 4028
//							A4 -> LED indicator interruption			
//							B4 -> boton		
//							B5 -> boton		  
//							B6 -> boton           
//							B7 -> boton	
//
//		   Conclusion:	The CCS does not perform well in the treatment of interruption 
//						the PORTB, so we'll have to read / write any pin 
//						the entire port PORTB or.
//////////////////////////////////////////////////////////////////////////////////

#include <16f648a.h>					//little of use
,NOWDT,NOPROTECT,PUT,NOLVP / / orders for the programmer
 (clock=4000000)				//Fosc=4Mhz
#use fast_io(b)
#use fast_io(a)


///Global variable declarations
;		

///ROLE CALL SHUTDOWN
()
{					
	output_high(pin_a4);		//interruption indicator on

!!!	
//	while(!input(PIN_B4) || !input(PIN_B5) || !input(PIN_B6) || !input(PIN_B7));	//eliminates rebounds
 <4:7> the PORTB. The CCS fails, so if we have the line read / write
(or any of its pins) Off we always entered the interruption!

	variable  ;					//we increased variable

(variable>0b00001001)		//Have you the last LED lit?
		variable=0;				//SI -> reset variable
	
	output_low(pin_a4);			//Interruption indicator off
}

///PROGRAM
(void)
{
	setup_oscillator(OSC_4MHZ);		//configured el 4MHz oscillator

 (0x00);				//door salida
 (0xFF);				//portb entry

(int_rb);		//Interrupt enable RB4:7
	enable_interrupts(GLOBAL);		//interrupts enabled

(pin_a4);				//interruption indicator off

{								//loop ...
		output_a(variable);			//slide show for the variable value
		}while(TRUE);				//...infinite
}

Lcd PIC16F648A I 24LC256 EEPROM
PIC16F648A lcd ve 24lc256 Eeprom

////////////////////////////////////////////////////////////////////////////////////
//							VsZeNeR'05		
//						   30/August/05
//						vszener@gmail.com
//	Program:	Write & external EEPROM 24LC256 read and display by lcd
//	Version:	0.0
//
//	Device: 16F648A PIC Compiler:	 CCS vs3.227
//	IDE: MPLAB IDE v7.21 Simulador:	 Proteus 6.7sp3
//
//	Notes: Is displayed by LCD screen(LM016L) the information recorded in the memory
//		   external 24LC256(eeprom) and then displayed by the LCD
//		   It uses local variables:
//				·dir-> position recording on the 24LC256 eeprom
//				·men1[] -> Contains 1 message to write to eeprom and display on lcd
//				·men2[] -> Contains 2 nd message to write to eeprom and display on lcd
//				·men3[] -> Contains 3 º message to write to eeprom and display on lcd
//				·men4[] -> Contains 4 th message to write to eeprom and display on lcd
//		   In the LCD screen displays the memory address where it is recorded
//		   message to be displayed and the corresponding message.
//		   Note that you have to put the directive NOLVP for the pin B4 is of 
//		   output. 
//	Connections:		A0 -> SCK external eeprom
//					A1 -> external eeprom SDA
//					B0 -> E		      
//					B1 -> RS			
//					B2 -> RW		
//					B4 -> D4		  
//					B5 -> D5            
//					B6 -> D6	
//					B7 -> D7                   
//////////////////////////////////////////////////////////////////////////////////

#include <16f648a.h>				//pic to use
(CLOCK=4000000)			//Fosc=4Mhz 
#fuses HS,NOPUT,NOPROTECT,NOBROWNOUT,NOLVP,NOWDT / / commands to the controller
.
#EEPROM_SCL defined PIN_A0 / / the eeprom anger connected
 <24256.c>					//external EEPROM 24LC256 library
  					//Royalty Free LCD

(void){ 
	int dir = 0;					//direction of EEPROM write and read messages
[]="VsZeNeR'05";	//declaration of ...
	char men2[]="Hello";
	char men3[]="Forum";
	char men4[]="TODOPIC!";		//...messages to write and read for 25LC256

(); 				//inicializa lcd
(); 			//initialize eeprom

("~ Writing in ...  n24LC256  n");
	delay_ms(500);
	write_ext_eeprom(you,men1);		//process of writing ...
	you    ;
	write_ext_eeprom(you,men2);
	you    ;
	write_ext_eeprom(you,men3);
	you    ;
	write_ext_eeprom(you,men4);		//...messages in the external eeprom
("\ffin writing in  n24LC25");
	delay_ms(1500);
	
	lcd_putc("\Leyendo >>> f ...  n");
 	for(dir = 0;you<4;dir++){			//bucle para leer mensajes en eeprom externa y muestra por lcd
		printf(lcd_putc,"\n %d ~ %s",dir,read_ext_eeprom(dir));
		delay_ms(1500);						//retraso para que se vea en pantalla los mensajes
		lcd_putc("\n                ");		//borrado 2ºlinea de lcd
		} 
	output_a(0b00);							//apago port a
	lcd_putc("\fFin de lectura!");
	
	for(;;){							//animacion...
		for(dir=1;dir<8;dir++){
			lcd_gotoxy(dir,2);
			lcd_putc("VsZeNeR'05");
			delay_ms(200);
			lcd_putc("\n                ");
			}
		for(dir=6;dir>1;you -){
			lcd_gotoxy(you,2);
			lcd_putc("VsZeNeR'05");
			delay_ms(200);
			lcd_putc("\n                ");
			}
		}								//...final		   
} 

5x7 Led Matrix
5x7 Led Matrix

//////////////////////////////////////////////////////////////////////////////////
//							VsZeNeR'05		
//						  19/December/05
//						vszener@gmail.com
//	Program:	Alphabet in arrays of LED's 5x7
//	Version:	0.0
//
//	Device: 16F648A PIC Compiler:	 CCS vs3.236
//	IDE: MPLAB IDE v7.30 Simulador:	 Proteus 6.7sp3
//
//	Notes: This program displays the alphabet in an array of LED's 5x7.
//		   Columns used in a decoder 4028 to make your sweep
//		   Connections:		A0 -> A 4028 DEC		      
//							A1 -> B 4028 DEC
//							A2 -> C 4028 DEC
//							A3 -> D 4028 DEC
//							B0 -> Fila 1 matriz 5x7
//							B1 -> Fila 2 matriz 5x7
//							B2 -> Fila 3 matriz 5x7
//							B3 -> Fila 4 matriz 5x7			
//							B4 -> Fila 5 matriz 5x7		
//							B5 -> Fila 6 matriz 5x7		  
//							B6 -> Fila 7 matriz 5x7           	
//////////////////////////////////////////////////////////////////////////////////

#include <16f648a.h>					//little of use
,NOWDT,NOPROTECT,PUT,NOLVP / / orders for the programmer
 (clock=4000000)				//Fosc=4Mhz
#use fast_io(a)
#use fast_io(b)

///Definitions global variables
[5],option = 0;

///ROLE CALL SHUTDOWN
()
{
	switch(option){	//select letra
 0:	letter[0]=0b00000001;	//In
[1]=0b01110110;
				letter[2]=0b01110110;
				letter[3]=0b01110110;
				letter[4]=0b00000001;	
				option    ;
				break;
		case 1:	letter[0]=0b01001001;	//B
[1]=0b00110110;
				letter[2]=0b00110110;
				letter[3]=0b00110110;
				letter[4]=0b00000000;	
				option    ;
				break;
		case 2:	letter[0]=0b00111110;	//C
[1]=0b00111110;
				letter[2]=0b00111110;
				letter[3]=0b00111110;
				letter[4]=0b01000001;	
				option    ;
				break;
		case 3:	letter[0]=0b01000001;	//D
[1]=0b00111110;
				letter[2]=0b00111110;
				letter[3]=0b00111110;
				letter[4]=0b00000000;	
				option    ;
				break;
		case 4:	letter[0]=0b00111110;	//E
[1]=0b00110110;
				letter[2]=0b00110110;
				letter[3]=0b00110110;
				letter[4]=0b00000000;	
				option    ;
				break;
		case 5:	letter[0]=0b01111110;	//F
[1]=0b01110110;
				letter[2]=0b01110110;
				letter[3]=0b01110110;
				letter[4]=0b00000000;	
				option    ;
				break;
		case 6:	letter[0]=0b01001110;	//G
[1]=0b00110110;
				letter[2]=0b00110110;
				letter[3]=0b00111110;
				letter[4]=0b01000001;	
				option    ;
				break;
		case 7:	letter[0]=0b00000000;	//H
[1]=0b01110111;
				letter[2]=0b01110111;
				letter[3]=0b01110111;
				letter[4]=0b00000000;	
				option    ;
				break;
		case 8:	letter[0]=0b00111110;	//I
[1]=0b00111110;
				letter[2]=0b00000000;
				letter[3]=0b00111110;
				letter[4]=0b00111110;	
				option    ;
				break;
		case 9:	letter[0]=0b01111111;	//J
[1]=0b00000000;
				letter[2]=0b00111110;
				letter[3]=0b00101110;
				letter[4]=0b01001111;	
				option    ;
				break;
		case 10:	letter[0]=0b00111110;	//K
[1]=0b01011101;
					letter[2]=0b01101011;
					letter[3]=0b01110111;
					letter[4]=0b00000000;	
					option    ;
					break;
		case 11:	letter[0]=0b00111111;	//The
[1]=0b00111111;
					letter[2]=0b00111111;
					letter[3]=0b00111111;
					letter[4]=0b00000000;	
					option    ;
					break;
		case 12:	letter[0]=0b00000000;	//M
[1]=0b01111101;
					letter[2]=0b01111011;
					letter[3]=0b01111101;
					letter[4]=0b00000000;	
					option    ;
					break;
		case 13:	letter[0]=0b00000011;	//N
[1]=0b01011111;
					letter[2]=0b01101111;
					letter[3]=0b01110111;
					letter[4]=0b00000011;	
					option    ;
					break;
		case 14:	letter[0]=0b00000011;	//Ñ
[1]=0b01011101;
					letter[2]=0b01101101;
					letter[3]=0b01110101;
					letter[4]=0b00000011;	
					option    ;
					break;
		case 15:	letter[0]=0b01000001;	//About
[1]=0b00111110;
					letter[2]=0b00111110;
					letter[3]=0b00111110;
					letter[4]=0b01000001;	
					option    ;
					break;
		case 16:	letter[0]=0b01111001;	//P
[1]=0b01110110;
					letter[2]=0b01110110;
					letter[3]=0b01110110;
					letter[4]=0b00000000;	
					option    ;
					break;
		case 17:	letter[0]=0b00000001;	//Q
[1]=0b00011110;
					letter[2]=0b00101110;
					letter[3]=0b00111110;
					letter[4]=0b01000001;	
					option    ;
					break;
		case 18:	letter[0]=0b01111001;	//R
[1]=0b00110110;
					letter[2]=0b01010110;
					letter[3]=0b01100110;
					letter[4]=0b00000000;	
					option    ;
					break;
		case 19:	letter[0]=0b01001110;	//The
[1]=0b00110110;
					letter[2]=0b00110110;
					letter[3]=0b00110110;
					letter[4]=0b00111001;	
					option    ;
					break;
		case 20:	letter[0]=0b01111110;	//T
[1]=0b01111110;
					letter[2]=0b00000000;
					letter[3]=0b01111110;
					letter[4]=0b01111110;	
					option    ;
					break;
		case 21:	letter[0]=0b01000000;	//U	
					letra[1]=0b00111111;
					letter[2]=0b00111111;
					letter[3]=0b00111111;
					letter[4]=0b01000000;	
					option    ;
					break;
		case 22:	letter[0]=0b01100000;	//The
[1]=0b01011111;
					letter[2]=0b00111111;
					letter[3]=0b01011111;
					letter[4]=0b01100000;	
					option    ;
					break;
		case 23:	letter[0]=0b01000000;	//W
[1]=0b00111111;
					letter[2]=0b01000111;
					letter[3]=0b00111111;
					letter[4]=0b01000000;	
					option    ;
					break;
		case 24:	letter[0]=0b00111011;	//X
[1]=0b01010111;
					letter[2]=0b01101111;
					letter[3]=0b01010111;
					letter[4]=0b00111011;	
					option    ;
					break;
		case 25:	letter[0]=0b01111110;	//And
[1]=0b01111101;
					letter[2]=0b00000011;
					letter[3]=0b01111101;
					letter[4]=0b01111110;	
					option    ;
					break;
		case 26:	letter[0]=0b00111100;	//The
[1]=0b00111010;
					letter[2]=0b00110110;
					letter[3]=0b00101110;
					letter[4]=0b00011110;	
					option = 0;
		}
	set_timer1(3036);				//TMR1 overflows every 0.5 s 								
}

void main(void)
{
	int i;	//variable counter

(INT_TIMER1);				//Interrupt enabled TIMER1
(T1_INTERNAL|T1_DIV_BY_8);		//configuracion TMR1
(65535);							//Load TMR1 overflow to an immediate
(GLOBAL);					//interrupts enabled

 (0x00);		//PORTB salida
 (0x00);		//carries out

{				//loop ...
		for(i=0;i<5;i++){		
			output_a(i);			//columnas
    		output_b(letra[i]);		//filas
   			delay_ms(10);			//pausa para poder verse
   			}
   	}while(TRUE);	//...infinito
}

LCD Kayan Yazı
LCD Kayan Yazı

////////////////////////////////////////////////////////////////////////////////////
//							VsZeNeR'05		
//						   29/August/05
//						vszener@gmail.com
//	Program:	Mov VsZeNeR'05 screen
//	Version:	0.0
//
//	Device: 16F648A PIC Compiler:	 CCS vs3.227
//	IDE: MPLAB IDE v7.21 Simulador:	 Proteus 6.7sp3
//
//	Notes: Is displayed by LCD screen(LM016L) as the word VsZeNeR'05 
//		   moves through screen, begins at 1 and ends at row 2nd row.
//		   It uses local variables:
//				·x -> index filas, char is signed because we need no negative
//				      for the lcd 2nd row appears first end of message.
//				·and -> index of columns: y=1 -> 1ºcolumna
//										  y=2 -> 2ºcolumna
//		   La 'x' is understood in the screen from 1 to 16 and 'and' from 1 to 2.
//		   Note that you have to put the directive NOLVP for the pin B4 is of 
//		   output. 
//
//	Connections:		B0 -> E		      
//					B1 -> RS			
//					B2 -> RW		
//					B4 -> D4		  
//					B5 -> D5            
//					B6 -> D6	
//					B7 -> D7                   
//////////////////////////////////////////////////////////////////////////////////

#include <16f648a.h>				//little of use
,NOWDT,NOPROTECT,PUT,NOLVP / / orders for the programmer
 (clock=4000000)			//Fosc=4Mhz
#define use_portb_lcd TRUE			//definir portb lcd
#include						//libreria manejo LCD

(void)
{
	car y = 1;					//indice columnas
	signed char x=1;			//index filas

();					//initializes lcd

(TRUE){		//loop ...
		lcd_gotoxy(x,and);		//cursor to write message
("VsZeNeR'05");	//the screen shows the message
(150);			
		x  ;					//increase index de filas
(x>16){				//Already shown? Entire message for row 1?
			x=-8;				//YES -> index row x = -8
;				//increase index columnas
(and> 2)				//Already shown? Message via 2nd column?
				y = 1;			//YES -> restoration index columna
			}
		lcd_putc("\f");			//screen clears  
		}				//...infinite
}

LCD DS1302 App
LCD DS1302 Uygulaması

////////////////////////////////////////////////////////////////////////////////////
//							VsZeNeR'05		
//						   09/September/05
//						vszener@gmail.com
//	Program:	Clock-Calendar DS1302
//	Version:	0.0
//
//	Device: 16F648A PIC Compiler:	 CCS vs3.227
//	IDE: MPLAB IDE v7.21 Simulador:	 Proteus 6.7sp3
//
//	Notes: Is displayed by LCD screen(LM016L) the date and time obtained by
//		   Reading the DS1302. Being able to change by using the Setup / Ok and up.
//		   It uses global variables:
//				·day-> dia ds1302
//				·mth -> between ds1302
//				·year -> year DS1302
//				·hour -> hora ds1302
//				·min -> minutos DS1302
//				·sec-> seconds ds1302
//				·menu -> variable set menu option shows
//				·flag -> variable count to approximately 130ms.
//				·var -> ajuste fine to overflowing each approx 130m.
//		   TMR0 is loaded with 0 for it either overflows into approx 65ms, we
//		   display and reset holding the DS1302 values ​​every 130ms approx therefore
//		   use a variable called flag that will be in charge of this task.
//		   At the start of the program must be set the clock, being the button 'up' the
//		   commissioned to go moving through menu options:time,minutes,....
//		   and the button 'Conf / Ok' in charge of setting the clock(when we see mode
//		   Time and Date) or manager leaving the options settings(when
//		   format we set the date and time).
//		   Note that you have to put the directive NOLVP for the pin B4 is of 
//		   output. 
//	Connections:		A0 -> RST DS1302
//					A1 -> SCLK DS1302
//					A2 -> I / O DS1302
//					A3 -> Button 'up'
//					A5 -> Button 'Conf / Ok'
//					B0 -> E		      
//					B1 -> RS			
//					B2 -> RW		
//					B4 -> D4		  
//					B5 -> D5            
//					B6 -> D6	
//					B7 -> D7
//					B3 -> Zumbador(beep)                   
//////////////////////////////////////////////////////////////////////////////////

#include <16f648a.h>				//pic to use
(CLOCK=4000000)			//Fosc=4Mhz 
#fuses HS,NOPUT,NOPROTECT,NOBROWNOUT,NOLVP,NOWDT,NOMCLR / / commands for him programmer
(a)
#use standard_io(b)
#use_portb_lcd define TRUE / / use the port b for lcd.
#RTC_IO defined PIN_A2
 					//Royalty Free rtc ds1302
  					//Royalty Free LCD

,mth,year,dow,hour,my,sec;	//variables for ds1302
;			//variables to configure menu

(void);
void hours(void);					
void minutos(void);
void day(void);
void mes(void);
void anio(void);
void beep(void);

///ROLE CALL SHUTDOWN
()
{
	if(flag> was){		//Already a 130ms approx?
		was -;			//YES -> decrease var ... 
		if(where == 0)
			var = 2;		//...fine adjustment of approx 130ms
;			//reset flag to tell approx 130ms
(day,mth,year,dow);		//coge give,month,año
      (hour,my,sec );		//takes time,minute,second
(lcd_putc,"\fFecha: %2X /% 2X /% 2X  nhours: %2X:%2X:%2X",day,mth,year,hour,my,sec);	//lcd 
		}
		
	set_timer0(0);		//reset TMR0
	flag  ;				//increase variable flag
}

///PROGRAM
(void){ 
	
	enable_interrupts(INT_TIMER0);				//Interrupt enabled TIMER0
(RTCC_INTERNAL,RTCC_DIV_256);	//TMR0 Interrupt configuration
(0);								//carga TMR0

(); 			//initializes lcd
(); 			//initializes rtc

("Clock Calendar  n VsZeNeR'05");	//presentation ...
	delay_ms(800);									//...initial

();								//menu is set to
(GLOBAL);					//interrupts enabled

 (;;){			//loop ...
		if(input(PIN_A5)==0){				//Pressing Conf ...
			while(!input(PIN_A5)){}			//eliminates rebounds
();
			set();
			}								//ve set up the menu
		} 				//...infinite	   
} 

///FUNCTION CONFIGURE
(void){
	disable_interrupts(GLOBAL);					//interrupts disabled

{
		switch(menu){
			case 0:	lcd_putc("\fConfigurar  th hour?");		//hours
(!input(PIN_A5)){
						while(!input(PIN_A5)){}
						beep();
						hours();
						menu=1;								//points next option
						}
					break;
			case 1: lcd_putc("\fConfigurar  nminutos?");		//minutes
(!input(PIN_A5)){
						while(!input(PIN_A5)){}
						beep();
						minutes();
						menu=2;								//points next option
						}
					break;
			case 2: lcd_putc("\fConfigurar  India?");			//days
(!input(PIN_A5)){
						while(!input(PIN_A5)){}
						beep();
						day();
						menu=3;								//points next option
						}
					break;
			case 3: lcd_putc("\fConfigurar  NMES?");			//months
(!input(PIN_A5)){
						while(!input(PIN_A5)){}
						beep();
						month();
						menu=4;								//points next option
						}
					break;
			case 4: lcd_putc("\fConfigurar  nanio?");		//years old
(!input(PIN_A5)){
						while(!input(PIN_A5)){}
						beep();
						anio();
						menu=5;								//points next option
						}
					break;
			case 5: lcd_putc("\fSalir  nConfigure?");		//out settings
(!input(PIN_A5)){
						menu=6;
						beep();
						}					
			}
			
		if(!input(PIN_A3)){				//button controls up ...
			while(!input(PIN_A3)){}
			menu  ;
			if(menu>5)
				menu=0;
			}							//...to show menu for lcd

(130);					//delay to see lcd
		}while(menu<6);
		
		menu=0;											//actualiza indices menu
		rtc_set_datetime(day,mth,year,dow,hour,min);	//nueva hora,minuto,...
		enable_interrupts(GLOBAL);						//activadas interrupciones
		set_timer0(0);									//carga TMR0
}
///FUNCION CONFIGURA HORAS
void horas(void){
	printf(lcd_putc,"\fConf.Horas:\nHora: %2X:%2X:%2X",hour,min,sec);	//muestra por lcd
	do{
		if(!input(PIN_A3)){						//¿se ha pulsado up?
			while(!input(PIN_A3)){}				//elimina rebotes
			hour++;								//SI -> incremento hour
			switch(hour){						//limits ...
				case 0x0A:	hour=0x10;break;		
				case 0x1A:	hour=0x20;break;
				case 0x24:	hour=0x00;
				}								//...hour
			printf(lcd_putc,"\Nhora: %2X:%2X:%2X",hour,my,sec);	//lcd sample per hour
			}
		}while(input(PIN_A5));
	while(!input(PIN_A5)){}			//eliminates rebounds
}
///Set FUNCTION MINUTES
(void){
	printf(lcd_putc,"\fConf.Minutos:\Nhora: %2X:%2X:%2X",hour,my,sec);	//lcd sample
{
		if(!input(PIN_A3)){				//Have you pressed up?
		while(!input(PIN_A3)){}			//eliminates rebounds
;							//YES -> min increase
(my){					//limits ...
			case 0x0A:	min = 0x10;break;
			case 0x1A:	min = 0x20;break;
			case 0x2A:	min = 0x30;break;
			case 0x3A:	min = 0x40;break;
			case 0x4A:	min = 0x50;break;
			case 0x5A:	min = 0x00;
			}							//...min
(lcd_putc,"\Nhora: %2X:%2X:%2X",hour,my,sec);	//lcd min sample
		}
		}while(input(PIN_A5));
	while(!input(PIN_A5)){}			//eliminates rebounds
}
///Set FUNCTION DAY
(void){
	printf(lcd_putc,"\fConf.Dias:\nFecha: %2X/%2X/%2X",day,mth,year);	//lcd sample
{
		if(!input(PIN_A3)){					//Have you pressed up?
			while(!input(PIN_A3)){}			//eliminates rebounds
;							//SI -> incremento day
			switch(day){					//limits ...
				case 0x0A:	day=0x10;break;
				case 0x1A:	day=0x20;break;
				case 0x2A:	day=0x30;break;
				case 0x32:	day=0x01;
				}							//...day
			printf(lcd_putc,"\fConf.Dias:\nFecha: %2X/%2X/%2X",day,mth,year);	//lcd sample day
			}
		}while(input(PIN_A5));
	while(!input(PIN_A5)){}			//eliminates rebounds
}
///Set FUNCTION MONTH
(void){
	printf(lcd_putc,"\fConf.Mes:\nFecha: %2X/%2X/%2X",day,mth,year);	//lcd sample
{
		if(!input(PIN_A3)){					//Have you pressed up?
			while(!input(PIN_A3)){}			//eliminates rebounds
;							//SI -> incremento mth
			switch(mth){					//limits ...
				case 0x0A:	mth=0x10;break;
				case 0x13:	mth=0x01;
				}							//...mth
		printf(lcd_putc,"\fConf.Mes:\nFecha: %2X/%2X/%2X",day,mth,year);	//lcd sample
			}
		}while(input(PIN_A5));
	while(!input(PIN_A5)){}			//eliminates rebounds
}
///FUNCTION SETTING YEAR
(void){
	printf(lcd_putc,"\fConf.Anio:\nFecha: %2X/%2X/%2X",day,mth,year);	//lcd sample
{
		if(!input(PIN_A3)){					//Have you pressed up?
			while(!input(PIN_A3)){}			//eliminates rebounds
;							//SI -> incremento mth
			switch(year){					//limits ...
				case 0x0A:	year=0x10;break;
				case 0x1A:	year=0x20;break;
				case 0x2A:	year=0x30;break;
				case 0x3A:	year=0x40;break;
				case 0x4A:	year=0x50;break;
				case 0x5A:	year=0x60;break;
				case 0x6A:	year=0x70;break;
				case 0x7A:	year=0x80;break;
				case 0x8A:	year=0x90;break;
				case 0x9A:	year=0x00;
				}							//...year
		printf(lcd_putc,"\fConf.Anio:\nFecha: %2X/%2X/%2X",day,mth,year);	//lcd sample
			}
		}while(input(PIN_A5));
	while(!input(PIN_A5)){}			//eliminates rebounds
}
///FUNCION BEEP
void beep(void){
	output_high(PIN_B3);	//active buzzer
(50);
	output_low(PIN_B3);		//buzzer off
}

Print individual letters on the LCD
LCD Üzerine tek tek harf yazdırma

////////////////////////////////////////////////////////////////////////////////////
//							VsZeNeR'05		
//						   26/August/05
//						vszener@gmail.com
//	Program:	ABC
//	Version:	0.0
//
//	Device: 16F648A PIC Compiler:	 CCS vs3.227
//	IDE: MPLAB IDE v7.21 Simulador:	 Proteus 6.7sp3
//
//	Notes: Is displayed by LCD screen(LM016L) the alphabet and back again 
//		   Note that you have to put the directive NOLVP for the pin B4 is of 
//		   output. 
//				·ABC[] -> Where it is stored vector alphabet
//				·x -> index to vector alphabet and column index for lcd
//			    ·and -> index to row lcd: y = 1 -> Row 1
//											y = 2 -> Row 2
//	Connections:		B0 -> E		      
//					B1 -> RS			
//					B2 -> RW		
//					B4 -> D4		  
//					B5 -> D5            
//					B6 -> D6	
//					B7 -> D7                   
//////////////////////////////////////////////////////////////////////////////////

#include <16f648a.h>				//little of use
,NOWDT,NOPROTECT,PUT,NOLVP / / orders for the programmer
 (clock=4000000)			//Fosc=4Mhz
#define use_portb_lcd TRUE			//definir portb lcd
#include						//libreria manejo LCD

(void)
{
	char alphabet[27]={' ','a','b','c','d','And','f','g','H','i','j','k','L','m','n','O','p','q','r','s','t','U','V','W','x','Y','Z'},x,y = 1;	//and variables defined table

();			//initializes lcd

{								//loop ...
	for(x=1;x<27;x++){				//bucle para mostrar digito
		if(y==1)					//1º fila del lcd
			lcd_gotoxy(x,y);
		else						//2º fila del lcd
			lcd_gotoxy((x-16),y);
		
		if(x>15)					//Already completed? 1st row lcd?
			y = 2;					//SI -> type in the 2nd row

(lcd_putc,"%c",ABC[x]);	//displays on screen the character
(300);					
		}
	printf(lcd_putc,"\f");	//clears the LCD screen
;					//reset index
	}while(TRUE);					//...infinite
}

4 Led Knight Riders
4 Ledli Kara Şimşek

////////////////////////////////////////////////////////////////////////////////////
//							VsZeNeR'04		
//						   12/August/05
//						vszener@gmail.com
//	Program:	Fantastic car
//	Version:	1.0
//
//	Device: 16F648A PIC Compiler:	 CCS vs3.227
//	IDE: MPLAB IDE v7.20 Simulador:	 Proteus 6.7sp3
//
//	Notes: Sweeping lighting LED's simulating the fantastic car
//		   Port B through instruction to rotate.
//
//				RB0 -> 1 º Led
//				RB1 -> 2 º Led
//				RB2 -> 3 º Led
//				RB3 -> 4 º Led
//////////////////////////////////////////////////////////////////////////////////

#include <16f648a.h>				//little of use
,NOWDT,NOPROTECT,PUT / / orders for the programmer
 (clock=4000000)			//Fosc = 4Mhz
(B)					//Port B as Output
(void)
{
	int led_on=0b0001;				//led a iluminar
(0xf0);				//portb as salida (some disabled)
	disable_interrupts(GLOBAL);		//all interrupts disabled

{								//loop ...
		
		do{		//LEFT lighting
;
			rotate_left(&led_on,1);
			delay_ms(300);
			}while(bit_test(led_on,3)==0);
		
		do{		//lighting to the right
;
			rotate_right(&led_on,1);
			delay_ms(300);
			}while(bit_test(led_on,0)==0);
			
		}while(TRUE);				//...infinite
}

8 Led Black lightning circuit
8 Ledli Kara şimşek circuit

////////////////////////////////////////////////////////////////////////////////////
//							VsZeNeR'04		
//						   14/August/05
//						vszener@gmail.com
//	Program:	Fantastic car
//	Version:	2.0
//
//	Device: 16F648A PIC Compiler:	 CCS vs3.227
//	IDE: MPLAB IDE v7.20 Simulador:	 Proteus 6.7sp3
//
//	Notes: Sweeping lighting LED's simulating the fantastic car
//		   Port B. Adaptation of the code in basic for lordlafebre 
//
//				RB0 -> 1 º Led
//				RB1 -> 2 º Led
//				RB2 -> 3 º Led
//				RB3 -> 4 º Led
//				RB4 -> 5 º Led
//				RB5 -> 6 º Led
//				RB6 -> 7 º Led
//				RB7 -> 8 º Led
//		   Cont in the variable values ​​be stored 1-2-4-8-16-32-64-128
//		   which in binary corresponds to the sequence 00000001-00000010-00000100...
//		   are the led's to illuminate, coinciding with the lighting sequence
//		   the fantastic coche(Ecuadorian version: fantastic car)
//////////////////////////////////////////////////////////////////////////////////

#include <16f648a.h>				//little of use
,NOWDT,NOPROTECT,PUT,NOLVP / / orders for the programmer
 (clock=4000000)			//Fosc = 4Mhz
(B)					//Port B as Output

(void)
{
	int i,account;						//variables defined
(0x00);				//portb as salida
(GLOBAL);		//all interrupts disabled

{								//loop ...
		Account = 1;						//boot ...
		i=1;						//...variables
		
		do{							//led's on derecha
			output_b(account);			//corresponding LED lit
(100);
			account = account * 2;
			i  ;					//increase the
			}while(i<8);
			
		i=1;						//reset valor i
		
		do{							//led's on izquierda
			output_b(cont);			//ilumino led correspondiente
			delay_ms(100);
			cont=cont/2;
			i++;					//incremento i
			}while(i<8);
			
		}while(TRUE);				//...infinito
}

PIC C Simple Sample Application List

16f628a led on-off
16f648a fantastic car for
16f648A game lights
aupa depo
betis
c&asm
ccp1 capture
ccp1_pwm
ccp1_pwm_vs2
key
fantastic car
Pacman
counter 0000a9999
counter 00_99
up counter
automatic counter
bcd counter 0A9
rev counter bcd
down counter
reversible counter
given
dispenser d shifts
ds1620
Error Int PORTB
hola_rot_7seg
PORTB int
int rb0
int rda eeprom 25lc256
int RDA EEPROM internal
int RDA EEPROM internaI
kit while
kit
lcd & 24lc256
lcd & keypad
lcd & rs232
lcd alphabet
new character lcd
lcd counter
lcd ds1302
lcd hola_mundo
lcd limites
lcd moving word
lcd read&write eeprom interna
limites 7Seg
matrix led 5x7
Blinking an LED
parpadeo4leds
pcf8591 adc
PCF8591 August
publish
lanes 7seg
rs232 & keypad
rs232 & leds
saa1064 16disp 7seg
saa1064 dinamico
saa1064 static
version_ahorro_1pin
vs_pcf8591
PIC C

Source: todopic.mforos.com Tüm dosyalar: microchip-pic-series-with-ccs-c-examples-simple-uygulamalar.rar

ccs c, Sample circuits, PIC C, PIC16F628, PIC16F648, PICC, simulation,

Elektronik

320volt yazarları

Author: gevv

Published on 07.07.2008 Examples of CCS C Microchip PIC Series Simple Applications total post 1780

Random Post

Paralel port dijital analog Convertor ses çıkış tda7050 STMicroelectronics VIPer Smps Tasarım Programı

Electronic Projects | 320volt.com Turkey in Turkey dealing with the development of IT and electronics to provide nice service to our people has been established to contribute to the development. | Infrastructure WordPress | simple electronic circuits | circuits archive