GUIA DOS

Page 1

ACTIVIDAD UNO Comunicaci贸n RS232

#include<16f876.h> //#fuses xt,nowdt,nolvp,noprotect #use delay(clock=4000000) #use RS232(baud=9600,xmit=pin_c6,rcv=pin_c7) #define use_portb_lcd true #include<lcd420.c> void main(){ int b,c,d; char k,g,f;

lcd_init(); printf("Hola Estudiantes\n"); printf(lcd_putc," Hola Estudiantes\n"); delay_ms(3000); lcd_putc("\f"); b=1;


while(true){ k=getc(); if((k-48)!=-5){ printf("%c",k); lcd_putc(k);}

if((k-48)==-5){ lcd_putc("\n"); } if((k-48)==-3){ printf("\f"); lcd_putc("\f"); lcd_gotoxy(1,1); } if((k-48)==0){ lcd_putc("\f"); delay_ms(100); } b++; }}


COMUNICION BIDIRECIONAL HIPERTERMINAL CON LCD

#include<16f877.h> #fuses xt,nowdt,nolvp,noprotect #use delay(clock=4000000) #use RS232(baud=9600,xmit=pin_c6,rcv=pin_c7) #define< use_portb_lcd #include<stdlib.h> #include<lcd420.c> void main(void){

char cadena1 [6]; char cadena2[6]; char cadena3[6]; signed long x; signed long y; signed long z; signed long suma; signed long resta; signed long producto; int division; signed long total;


while (true) { printf("introduzca el valor de x, y pulse enter: \r"); gets(cadena1); x=atoi(cadena1); printf("x=%ld\r",x); printf("introduzca el valor de y,y pulse enter:\r"); gets(cadena2); y=atoi(cadena2); printf("y=%ld\r",y); printf("introduzca el valor de z,y pulsar enter:\r"); gets(cadena3); z=atoi(cadena3); printf("z=%ld\r",z); printf("el valor de sapo es: %d bytes\r",sizeof(y)); suma=x+y+z; resta=x-y-z; producto=x*y*z; division=x/y/z; total=((x+y+z)+(x-y-z)+(x*y*z)+(x/y/z)); printf(" x+y+z: %ld\n\r",suma); lcd_init(); printf(" x-y-z: %ld\r",resta); lcd_gotoxy(1,1); printf(lcd_putc," x-y-z: %ld ",resta); printf(" x*y*z: %ld\r",producto); lcd_gotoxy(1,2); printf(lcd_putc," x*y*z: %ld ",producto); printf(" x/y/z: %d\r",division); lcd_gotoxy(1,3); printf(lcd_putc," x/y/z: %d ",division); printf("resto:%ld\r",x%y); printf(" total: %ld\r",total); } }


MODULO PWM

#include<16f877.h> #device adc=8 #fuses XT,NOWDT,NOPROTECT,NOPUT,NOBROWNOUT,NOLVP #use delay (clock=4000000) #use RS232(baud=9600,xmit=pin_c6,rcv=pin_c7) #define use_portb_lcd true #include<lcd.c> const float escala = 255; const float d_max = 2000; void calcula_duty(int val, int valur,float&duty) { duty=(val*d_max)/escala; valur=duty; } void main(void){ int valor; float duty; int valur; lcd_init(); delay_ms(100);


lcd_gotoxy(1,1); lcd_putc("f=5000Hz->T=2ms"); lcd_gotoxy(1,2); setup_ccp1(CCP_PWM); // configura ccp1 como pwm setup_timer_2(T2_DIV_BY_16,124,1); // f=500Hz (T=2ms) setup_adc(adc_clock_div_32); // selecciona reloj setup_adc_ports(AN0); // RA0 analogico set_adc_channel (0); while(true){ valor=read_adc (); // lee valor RA0 set_pwm1_duty (valor); // establece duty com valor calcula_duty(valor,valur,duty);// escala el duty lcd_gotoxy(8,2); printf(lcd_putc,"%3.2f",duty);//muestra el resultado printf(" \f %3.2f",duty);//muestra el resultado puts("valur");//muestra el resultad } } GENRADOR DE FUNCIONES CON TIMER 0

#include<16f877.h> //#fuses #use delay(clock=4000000) #use fast_io(B) #int_RTCC


RTCC_isr(){ output_toggle(PIN_b7); set_timer0(198); } void main(void){ set_tris_b(0x00); output_low(pin_b7); setup_timer_0(RTCC_DIV_8); set_timer0(198); enable_interrupts(int_RTCC); enable_interrupts(global); while(true); }


DESARROLLO DE PROTOCOLO I2C CON PERIFERICOS

#include<16f877.h> #define adc=8 #fuses xt, nolvp, nowdt, noput, nobrownout, noprotect #use delay (clock=4000000) #use rs232 (baud=9600, xmit=pin_c6, rcv=pin_c7)

//#include <ds1307.c> #define use_portb_lcd true #include <lcd420.c> #use i2c (master,fast, scl=pin_c3,sda=pin_c4) #define ds1307_scl pin_c3 #define ds1307_sda pin_c4 #use i2c (master, sda=ds1307_sda, scl=ds1307_scl) void ds1307_init (void) // rutina para inicializar el reloj { output_float(ds1307_sda); output_float(ds1307_scl); } void write_ds1307_putc (byte address, byte data) // rutina para escriir datos { short int status; // declarar el tama単o del registro i2c_start();


i2c_write(0xd0); i2c_write(address); i2c_write(data); i2c_stop(); i2c_start(); status=i2c_write(0xd0); while (status==1) { i2c_start(); status=i2c_write(0xd0); } } byte read_ds1307(byte address) // rutina para leer { byte data; i2c_start(); i2c_write(0xd0); i2c_write(address); i2c_start(); i2c_write(0xd1); data=i2c_read(0); i2c_stop(); } void main (void) { int8 sec,min,hora,fecha,dia,mes,anio; int8 ho,mini,seco; lcd_init(); delay_ms(50); ds1307_init(); sec=read_ds1307(0); write_ds1307_putc(0,sec=0x50); write_ds1307_putc(1,min=0x59); write_ds1307_putc(2,hora=0x12); write_ds1307_putc(3,dia=0x06); write_ds1307_putc(4,fecha=0x17); write_ds1307_putc(5,mes=0x03); write_ds1307_putc(6,anio=0x12); while (true) { sec=read_ds1307(0); min=read_ds1307(1); hora=read_ds1307(2); dia=read_ds1307(3);


fecha=read_ds1307(4); mes=read_ds1307(5); anio=read_ds1307(6); putc(0x0c); delay_ms(100); lcd_gotoxy(1,1); printf(lcd_putc,"\f///Hola Jose luis////"); lcd_gotoxy(1,2); printf(lcd_putc,"///hora:%02x:%02x:%02x////",hora,min,sec); lcd_gotoxy(1,3); printf(lcd_putc,"//////dia:%02x////////",dia); lcd_gotoxy(1,4); printf(lcd_putc,"///fecha:%02x:%02x:%02x///",fecha,mes,anio); printf("hora:%02x:%02x:%02x",hora,min,sec); printf("dia:%02d",dia); printf("fecha:%02x:%02x:%02x",fecha,mes,anio); } }

PROGRAMA QUE UTILICE MEMORIA EEPROM

#include <16F877.h> //Configuraci贸n de los fusibles. //#FUSES NOWDT, XT, NOPUT, NOPROTECT, NOBROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG #use delay(clock=4000000) //Frecuencia de reloj 4MHz #byte puerto_D = 0x08 // Identificador para el puerto C.


#int_EXT void EXT_isr( void ) { if ((read_eeprom(0)==0x99)||(read_eeprom(0)==0xFF)) { write_eeprom(0,0); puerto_D=read_eeprom(0); } else if ((read_eeprom(0) & 0x0F)<0x09) { write_eeprom(0,(read_eeprom(0))+1); puerto_D=read_eeprom(0); } else if ((read_eeprom(0) & 0x0F)>=0x09){ write_eeprom(0,(read_eeprom(0))+7); puerto_D=read_eeprom(0); } } void main() { set_tris_b(0xFF); //Puerto B como entrada set_tris_d(0x00);//Puerto D como salida enable_interrupts(GLOBAL); // Se habilita la interrupci贸n global enable_interrupts(INT_EXT); // Se habilita la interrupci贸n externa puerto_D =0xFF; //inicializo puerto D //write_eeprom(0,0xFF);//Resetear EEPROM while(true) { //Resto del programa } }


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.