Você está na página 1de 19

#include <18F452.

h>
#use delay (clock=4000000)
Pisca Leds #fuses NOWDT

main()
{

while(true)
{
output_high(PIN_B0);
delay_ms(500);
output_low(PIN_B0);
output_high(PIN_B1);
delay_ms(500);
output_low(PIN_B1);
output_high(PIN_B2);
delay_ms(500);
output_low(PIN_B2);
output_high(PIN_B3);
delay_ms(500);
output_low(PIN_B3);
}
}
#include <18f452.h>
#use delay (clock=4000000)
Pisca Leds:
Declaração de void ini() // função início
{
funções ex: void ini(); output_high(PIN_B0);
void estado1(); output_high(PIN_B1);
output_high(PIN_B2);
output_high(PIN_B3);
}
void estado1() // função estado 1
{
output_high(PIN_B0);
output_low(PIN_B1);
output_low(PIN_B2);
output_low(PIN_B3);
}
void estado2() // função estado 2
{
output_low(PIN_B0);
output_high(PIN_B1);
output_low(PIN_B2);
output_low(PIN_B3);
}
void estado3() // função estado 3
{
Pisca Leds: output_low(PIN_B0);
Declaração de output_low(PIN_B1);
funções output_high(PIN_B2);
ex: void estado3(); output_low(PIN_B3);
}

void estado4() // função estado 4


{
output_low(PIN_B0);
output_low(PIN_B1);
output_low(PIN_B2);
output_high(PIN_B3);
}

void atraso() // função de atraso


{
delay_ms(500);
}
Pisca Leds por main()
{
invocação de ini(); // Invocação da função início
funções na função atraso(); // Invocação da função atraso
principal main() while(true)
{
estado1(); // Invocação da função estado 1
atraso();

estado2();
atraso();

estado3();
atraso();

estado4();
atraso();
}
}
Acende Led por #include <18F452.h>
verificação da #use delay (clock=4000000)
condição de estado
main()
do bit A0, PortoA. {
while (true) // Enquanto for verdadeiro faz
{
if (input(PIN_A0)) // Se o pino A0 == High faz:
output_high(PIN_B0);

else // Se não (A0!= de High) faz:


output_low(PIN_B0);
}
}
#include <18f452.h>
 Escrita no #use delay(clock=4000000)
lcd #include <mod_lcd2.c>
main()
{
lcd_ini();
while(true)
{
lcd_escreve('\f');
lcd_escreve(" 10PA "); delay_ms(1000);
output_high(PIN_B0);
output_high(PIN_B1);
output_high(PIN_B2);
output_high(PIN_B3);
lcd_escreve('\f');
lcd_escreve("\nLinguagem C!");
delay_ms(1000);
}
}
#include <18F452.h>
#use delay (clock=4000000)
#include <mod_lcd2.c>
 Contador e
Escrita no main ()
{
LCD int cont=0, entb1=0;
lcd_ini();

while (true)
{
lcd_escreve('\f');
lcd_escreve(" 10PA ");
if (input(PIN_B1)==1 && cont<5 && entb1==cont)
cont= cont + input(PIN_B1);
if (input(PIN_B1)==0 && entb1<cont)
entb1++;
if(cont==5)
{
cont=0; entb1=0;
output_high(PIN_B0);
delay_ms(1);
output_low(PIN_B0);
lcd_escreve("\nCont Ok!");
}
}
}
#include <18f452.h>
#use delay (clock=4000000)
 Escrita no //#fuses NOWDT
LCD do valor #include <mod_lcd2.c>
da contagem void main()
{
int cont=0;
lcd_ini();

while (true)
{
lcd_escreve('\f');

if (input(pin_b0)==1) // Contador Melhorado


{
cont++;
printf(lcd_escreve,“Valor Contador=%u\r\n", cont);

while(input(pin_b0)==1){}

}
}
}
#include <18f452.h>
#use delay (clock=4000000)
 Cálculo da #use rs232 (baud=19200, xmit=pin_c6, rcv=pin_c7)
#fuses NOWDT
Área do #include <mod_lcd2.c>
Círculo
#define pi 3.142 // Define que pi toma este valor

void main()
{

int x=0;
float area;
int1 sair=0;

while (true)
{
while (sair==0)
{
if (input(pin_a4)==0)
x++;
if (input(pin_b0)==0)
sair=1;
else
sair=0;
 Cálculo da
lcd_ini();
Área do lcd_escreve('\f');
Círculo lcd_pos_xy(1,1);
(Continuação) printf(lcd_escreve, "%u", x);
delay_ms(500);

}
//lcd_ini();
lcd_escreve('\f');
lcd_pos_xy(1,1);
area=pi*x;
printf(lcd_escreve, "A area e %f", area);
delay_ms(2000);

}
}
#include <18f452.h>
#use delay (clock=4000000)
 Função: #use rs232 (baud=19200, xmit=pin_c6,
switch case rcv=pin_c7)
#fuses NOWDT
#include <modlcd.c>

void main()
{
int ch;
while (true)
{
ch=getch();
switch (ch)
{
case '1': printf("1\n\r"); break;
case '2': printf("2\n\r"); break;
default: printf("outra coisa\n\r");
}
printf("\r\n\n");
}
}
#include <18f452.h>
#use delay (clock=4000000)
//#fuses NOWDT
 Variável #use rs232(baud=19200, xmit=pin_c6, rcv=pin_c7)
Global.
long int somatorio=0; // Variável Global
Programa
Somatório void soma( int valor)
{
long int conta;
somatorio=somatorio+valor;
printf("A soma de 0");
for (conta=1; (conta<valor+1); conta++)
printf("+%lu", conta);
printf(" eh igual a %lu\r\n", somatorio);
}

void main()
{
int conta;
somatorio=0;
for (conta=1; conta<40; conta++)
{
soma(conta);
}
printf("\n");
}
#include <18F452.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
 Leitura de #use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6,
um entrada rcv=PIN_C7)
analógica
#include <mod_lcd12.c>
#include "math.h"

long int x=0; // %lu


float a=0.00, y=0.00, z=0.00; // %a.bf
int w=0; // %u
long int t=100; // delay na amostragem
long int k=50; // nº de amostras
long int i=0;

void main(){

setup_adc_ports(RA0_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
lcd_ini();
 Leitura de do {
x=0;
um entrada delay_ms(t);
analógica for(i=1;i<=k;i++){
(continuação) x=x+read_adc();delay_ms(t);
}
a=x/k;
z=a*0.01953125; // 5/256 =
0,01953125
y=52*z-52;
w=y;
printf(lcd_escreve, "\fbin= %f ",a);
printf(lcd_escreve, "\ndec= %f ",z);
delay_ms(2000);
printf(lcd_escreve, "\ftemp= %f ",y);
printf(lcd_escreve, "\ntemp= %u",w);

} while (TRUE);
}
Programa #include <18f452.h>
#use delay(clock=4000000)
final Contador
#include "mod_lcd2.c" //Inclui a Livraria do LCD.
até cinco de
10 Séries #define t1 10000 /*t1: Tempo de espera igual a delay_ms(10000);*/
#define t2 2000
#define t3 10

/******************************************************/
char total[10]; //Matriz do tipo carácter (char) com 10 células de dados, Variável Global.

/******************************************************/
void inimat( ) /*inimat: Apaga ou inicializa a Matriz, ficando uma matriz de zeros.*/
{
int i=0;
for (i=0; i<10; i++)
{
total[i]=0;
}
}
/******************************************************/
Programa void gmat( int valor) /*gmat: Guarda na Matriz total[10] o número de contagens.*/
{
final Contador
total[valor]='n';
até cinco de }
10 Séries
(continuação) /******************************************************/

tcmat( ) /* tcmat: Devolve o total das contagens(até 5)registadas na Matriz até ao momento
. da chamada da função.*/
{
int tcont=5, i=0; // tcont=5 porque no prog. principal cada contagem vai até cinco.

while (total[i]== 'n' && i<10)


{
i++;
}
tcont*=i;
return tcont;
}
Programa void main() // Programa principal.
{
final Contador
int cont=0, ncont=1, pemat=0;
até cinco de lcd_ini(); inimat( );
10 Séries lcd_escreve('\f'); delay_ms(t3);
(continuação) while (true)
{
printf(lcd_escreve,"N'Serie~%u|N'C~%u", ncont,cont);
lcd_escreve("\nTotais Press~RA4"); /*Pressionando o Botão RA4 do PICDEM 2
PLUS vemos o total que foi contado até
ao momento.*/

if (input(pin_B0)==0) /*Botão da Contagem B0. Este pino na PICDEM 2 PLUS está


inicialmente no estádo lógico "1".*/
{
cont++;
while(input(pin_B0)==0){} /*Não sai do ciclo (While) enquanto estiver a carregar
no Botão B0.(O ciclo não faz nada)*/

lcd_escreve('\f'); delay_ms(t3);
}
Programa if (input(pin_A4)==0)
{
final
lcd_escreve('\f'); delay_ms(t3); /*Este pino na PICDEM 2 PLUS está
Contador até inicialmente no estádo lógico "1".*/
cinco de 10 printf(lcd_escreve,"Seris Finaliz~%u\nTotal Contado~%u ", ncont-1, tcmat( ));
Séries delay_ms(t1);
(continuação) while(input(pin_A4)==0){}
lcd_escreve('\f'); delay_ms(t3);
}

if(cont==5 && ncont<=10)


{
lcd_escreve('\f'); delay_ms(t3);
printf(lcd_escreve,"N'Serie~%u|N'C~%u", ncont,cont);
lcd_escreve("\nTotais Press~RA4"); delay_ms(1000);
gmat(pemat); pemat++;
cont=0; ncont++;
}
Programa while (ncont>10)
{
final Contador
lcd_escreve('\f'); delay_ms(t3);
até cinco de
10 Séries printf(lcd_escreve,"Seris Finaliz~%u\nTotal Contado~%u ", ncont-1,
(continuação) tcmat( )); delay_ms(t1);

lcd_escreve('\f'); delay_ms(t3);
lcd_escreve(" >FIM CONTAGEM< ");
lcd_escreve("\nINICIALIZAR!~RA4"); delay_ms(t1);
if (input(pin_A4)==0)
{
lcd_escreve('\f'); delay_ms(t3);
inimat( ); ncont=1; pemat=0;
lcd_escreve(" MEMORIA VAZIA! \nPRONTO A CONTAR!");
delay_ms(t1);
while(input(pin_A4)==0){}
lcd_escreve('\f'); delay_ms(t3);
}
}
}
}

Você também pode gostar