Ciao, a che punto sei? Comunque sia, qui sotto ti allego il sorgente di un piccolissimo programma, da me testato con il tuo circuito.
Se vuoi tutto il pacchetto, senza dover ricompilare, dimmi come fare per renderlo disponibile o se posso inviartelo via mail. ciao per ora Angelo
N.B. Ricorda di settare Mp Lab per il pic 16 F 84; nel programma sono gia' presenti i settaggi di configurazione per i fusibili (Oscillatore ecc.). Il led posto su RB 0 lampeggia cambiando stato ogni 500 mSec. circa.
// // INIZIO PROGRAMMA: // // // File template per i microprocessori Pic 16F84 // Contiene le inizializzazioni indispensabili // per la programmazione in C Hi-Tech //
// //////////////////////////////////////////////////////////////////////////////// // // // Programma per Brunix // // // // Rev. 01.00 Rc 0 // // // // J.E.Pi // // 26 Giugno 2006 // // Angelo Raglianti // // // //////////////////////////////////////////////////////////////////////////////// //
// //////////////////////////////////////////////////////////////////////////////// // // // Files da includere // // // //////////////////////////////////////////////////////////////////////////////// //
#include
// //////////////////////////////////////////////////////////////////////////////// // // // Inizializzazione CPU e Release // // // //////////////////////////////////////////////////////////////////////////////// //
// // Compilatore Hi-Tech C // Micro Pic 16 F 84 //
// //////////////////////////////////////////////////////////////////////////////// // // // Configurazione fuses // // // //////////////////////////////////////////////////////////////////////////////// //
__CONFIG (RC & WDTDIS & PWRTEN & UNPROTECT);
// ////////////////////////////////////////////////////////////////////////////// // // // Inizializzazione del numero di revisione del programma // // // ////////////////////////////////////////////////////////////////////////////// //
__IDLOC(0001); //Revisione 00.01
// ////////////////////////////////////////////////////////////////////////////// // // // Dichiarazione delle variabili // // // ////////////////////////////////////////////////////////////////////////////// //
static bit b_ledlamp @ ((unsigned char) &PORTB*8+0); // Led lampeggiante
#define ledon 0 // Led acceso #define ledoff 1 // Led spento #define ledtoggle PORTB ^= 0x01
#define mezzosecondo 10800
static unsigned char uc_MaxFlash = 224; static unsigned char tmpcount;
static unsigned long sec; static unsigned long tmpsec;
unsigned char *ptrbufdat;
// ////////////////////////////////////////////////////////////////////////////// // // // Struttura di un campo di bit // // // ////////////////////////////////////////////////////////////////////////////// //
struct { unsigned char flint : 1; } flag ;
// ////////////////////////////////////////////////////////////////////////////// // // // Funzione di interrupt // // // ////////////////////////////////////////////////////////////////////////////// //
// Funzione per vettore di interrupt legata a Timer0 (RTCC)
static void interrupt isr(void) { asm ("NOP"); asm ("NOP"); asm ("NOP"); asm ("NOP"); asm ("NOP"); asm ("NOP"); TMR0 = 255 - tmpcount; T0IF = 0; flag.flint = 1; //Ogni 100 uSec. flag.flint = 1 }
// ////////////////////////////////////////////////////////////////////////////// // // // Prototipi delle funzioni // // // ////////////////////////////////////////////////////////////////////////////// //
void ritardo(unsigned int uivolte); void initint(void); void initport(void); void initvar(void);
// ////////////////////////////////////////////////////////////////////////////// // // // Funzione main // // // ////////////////////////////////////////////////////////////////////////////// //
main() { initport(); initvar(); initint();
ei(); // Abilita general interrupt
while(1) { ritardo (mezzosecondo); ledtoggle; } }
// ////////////////////////////////////////////////////////////////////////////// // // // Funzioni definite dall'utente // // // ////////////////////////////////////////////////////////////////////////////// //
// ////////////////////////////////////////////////////////////////////////////// // // // Funzione di ritardo software legata a interrupt // // // ////////////////////////////////////////////////////////////////////////////// //
void ritardo(unsigned int uivolte) { while (uivolte) { uivolte--; } }
/* // ritardo x uivolte interrupt da 100 uSec. cadauno
void ritardo(unsigned int uivolte) { while (uivolte) { flag.flint = 0; while (!flag.flint) { ; } uivolte--; } }
*/
// ////////////////////////////////////////////////////////////////////////////// // // // Fine delle funzioni utente // // // ////////////////////////////////////////////////////////////////////////////// //
// //**************************************************************************** // //**************************************************************************** // //**************************************************************************** //
// ////////////////////////////////////////////////////////////////////////////// // // // Funzioni di inizializzazione // // // ////////////////////////////////////////////////////////////////////////////// //
// //**************************************************************************** // //**************************************************************************** // //**************************************************************************** //
// ////////////////////////////////////////////////////////////////////////////// // // // Inizializzazione del Timer0 per interrupt // // // ////////////////////////////////////////////////////////////////////////////// //
void initint(void) { // Option Regiter "OPTION" // bit 7 = RBPU neg. = 0 pullup enabled // bit 6 = INTEDG = 1 rising edge int // bit 5 = TOCS = 0 int clk cycle(clkout) // bit 4 = T0SE = 0 increment on l to h // bit 3 = PSA = 0 prescaler to TMR0 // bit 2-1-0: PS2-PS1-PS0 // 000 = 1 : 2 // 001 = 1 : 4 // 010 = 1 : 8 // 011 = 1 : 16 // 100 = 1 : 32 // 101 = 1 : 64 // 110 = 1 : 128 // 111 = 1 : 256 OPTION = 0b11000011; // 1 : 16
// INTCON REGISTER (ADDRESS 0Bh, 8Bh) // bit 7: GIE: Global Interrupt Enable bit // 1 = Enables all un-masked interrupts // 0 = Disables all interrupts // bit 6: EEIE: EE Write Complete Interrupt Enable bit // 1 = Enables the EE write complete interrupt // 0 = Disables the EE write complete interrupt // bit 5: T0IE: TMR0 Overflow Interrupt Enable bit // 1 = Enables the TMR0 interrupt // 0 = Disables the TMR0 interrupt // bit 4: INTE: RB0/INT Interrupt Enable bit // 1 = Enables the RB0/INT interrupt // 0 = Disables the RB0/INT interrupt // bit 3: RBIE: RB Port Change Interrupt Enable bit // 1 = Enables the RB port change interrupt // 0 = Disables the RB port change interrupt // bit 2: T0IF: TMR0 Overflow Interrupt flag bit // 1 = TMR0 has overflowed (must be cleared in software) // 0 = TMR0 did not overflow // bit 1: INTF: RB0/INT Interrupt flag bit // 1 = The RB0/INT interrupt occurred // 0 = The RB0/INT interrupt did not occur // bit 0: RBIF: RB Port Change Interrupt flag bit // 1 = When at least one of the RB7:RB4 pins changed state (must be cleared in software) // 0 = None of the RB7:RB4 pins have changed state INTCON = 0b10100000; // Abilita GIE e T0IE (T0IF = 0) }
// ////////////////////////////////////////////////////////////////////////////// // // // Inizializzazione delle porte di I/O // // // ////////////////////////////////////////////////////////////////////////////// //
void initport(void) { PORTA = 0x00; PORTB = 0x00; //Port Reset TRISA = 0b00001000; //RA3 = Input TRISB = 0b00000000; //RB tutti Out b_ledlamp = ledon; //Led Lampeggiante acceso di default }
// ////////////////////////////////////////////////////////////////////////////// // // // Inizializzazione delle variabili // // // ////////////////////////////////////////////////////////////////////////////// //
void initvar(void) { tmpcount = 29; //Pre = 1:16 tClk=20MHz/4=5=200nSec. //Per 100uS. TMR0=29*(200ns*16)=92.8uSec. TMR0 = 255 - tmpcount; tmpsec = sec; b_ledlamp = 0; flag.flint = 0; }
// // Fine programma //