3_detectorPrimos

download 3_detectorPrimos

If you can't read please download the document

description

Pic16f883

Transcript of 3_detectorPrimos

//Determina si un nmero entre 0 y 255 es primo// PIC16F883 Configuration Bit Settings#include #include // CONFIG1#pragma config FOSC = XT // Seleccionamoe el Reloj externo de 4MHz#pragma config WDTE = OFF // Apago el Perro Guardin, (es un contador que cuando se desbora resetea el micro)#pragma config PWRTE = ON // Retardo de encendido del Micro (60ms) mientras se estabiliza#pragma config MCLRE = ON // Habilitamos el Master Clear#pragma config CP = OFF // Desabilito la proteccin para poder escribir en el micro (programarlo)#pragma config CPD = OFF // Desabilito la proteccin para poder escribir en el micro (programarlo)Data Code Protection bit (Data memory code protection is disabled)#pragma config BOREN = ON // Reset ante una caida de tensin en la alimentacin.#pragma config IESO = ON // En caso de haber clock externo, activando este bit el clk interno le ayuda al externo mientras se estabiliza.#pragma config FCMEN = ON // Si falla el clk externo el interno le ayuda.#pragma config LVP = OFF // Low Voltage Programming Enable bit (RB3 pin has digital I/O, HV on MCLR must be used for programming)// CONFIG2#pragma config BOR4V = BOR40V // Brown-out Reset Selection bit (Brown-out Reset set to 4.0V)#pragma config WRT = OFF // Flash Program Memory Self Write Enable bits (Write protection off)#define _XTAL_FREQ 4000000 //Frecuencia de Oscilador//Funcin Inicializacin de puertos Ac Inicializamos todo lo que tenga que ver con puertos.void port_init(){ ANSEL=0; //Deshabilita la entrada Anloga ANSELH=0; //Deshabilita la entrada Anloga TRISA=0b00000001; //RA0 es entrada TRISB=0b00000000; //Todo el puerto B es salida PORTB=0b00000000;}//Funcin Principalvoid main(void){ port_init(); int num=0; int div=0; while(1) { num=PORTA & 0b11111111; //and bit a bit for (int i=0; i