Last active
August 29, 2015 14:25
-
-
Save JulioAlexanderAguilarAngulo/17766bfc5b6a79ec6c79 to your computer and use it in GitHub Desktop.
Display Multiplex Driving with microcontroller (PICMicro) using interrupts and some tweaks....
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Julio Alexander Aguilar Angulo. 25 Juillet 2015 | |
* Created: jeu. juil. 23 2015 | |
* Processor: PIC16F648A - Compiler: MPLAB XC8*/ | |
#include <xc.h> | |
#include <stdint.h> | |
#include <pic16f648a.h> | |
// fuse configuration | |
#pragma config CP=OFF, CPD=OFF, BOREN=OFF, WDTE=OFF//SWDTEN | |
#pragma config PWRTE=ON, FOSC=INTOSCIO, MCLRE=OFF | |
#pragma config LVP=OFF//ON PLLEN=ON,BORV=LO,, WRT=OFF | |
// diverse compiler's parameters | |
#define _XTAL_FREQ 4000000 // 4MHz | |
#define FOSC 4000000 // 4MHz | |
// 7 segments = gfedcba | |
uint8_t segs[]={0b0111111,0b0000110,0b1011011,0b1001111,0b1100110,0b1101101,0b1111101,0b0000111, 0b1111111,0b1101111}; | |
uint8_t sels[]={0b1000,0b100,0b10,0b01}; | |
uint16_t par[]={1,10,100,1000}; | |
uint8_t buffer_mcdu[]={0,0,0,0}; | |
uint8_t i,j; | |
uint8_t it; | |
uint16_t counter; | |
//---------------------------------------- | |
void Config_GPIOs(void); | |
void Delay1(void); | |
void Convert(uint16_t counter); | |
void interrupt TIM0int(void); | |
void ConfigInterrupts(void); | |
//---------------------------------------- | |
// Interrupt Handler | |
void interrupt TIM0int(void) | |
{ | |
if (INTCONbits.TMR0IF ==1) // timer 0 interrupt flag | |
{ | |
INTCONbits.TMR0IF = 0; // clear the flag | |
INTCONbits.TMR0IE = 1; // reenable the interrupt | |
TMR0 = 6; // reset the timer preset count | |
PORTB=0x00; | |
PORTB=segs[buffer_mcdu[i]]; | |
PORTA=~sels[i]; | |
i++; | |
if (i==4) | |
{ i=0; | |
j++; | |
if (j==50) | |
{ | |
j=0; | |
counter++; | |
Convert(counter); | |
} | |
} | |
} | |
} | |
//--------------------------------------------------- | |
void main() | |
{ | |
Config_GPIOs(); | |
ConfigInterrupts(); | |
i=0;j=0; counter=0; | |
while (1) { } | |
} | |
//-------------------------- | |
void Config_GPIOs(void) | |
{ | |
CMCON=0x07;//analog off | |
TRISA=0; | |
TRISB=0; | |
PORTA=0x00; | |
PORTB=0x00; } | |
void Delay1(void) | |
{ uint16_t tmp; | |
tmp=800; | |
while (tmp>0){tmp--;} | |
} | |
void Convert(uint16_t Val) | |
{ | |
uint16_t Valt,part; | |
Valt=Val; | |
for(it=3;it>0;it--) | |
{ part=par[it]; buffer_mcdu[it]=Valt/part;Valt %=part;} | |
buffer_mcdu[0]=Valt; | |
} | |
void ConfigInterrupts(void) | |
{ | |
OPTION_REGbits.T0CS = 0; // bit 5 TMR0 Clock Source Select bit...0 = Internal Clock (CLKO) 1 = Transition on T0CKI pin | |
OPTION_REGbits.T0SE = 0; // bit 4 TMR0 Source Edge Select bit 0 = low/high 1 = high/low | |
OPTION_REGbits.PSA = 0; // bit 3 Prescaler Assignment bit...0 = Prescaler is assigned to the Timer0 | |
OPTION_REGbits.PS2 = 0; // bits 2-0 PS2:PS0: Prescaler Rate Select bits | |
OPTION_REGbits.PS1 = 1; | |
OPTION_REGbits.PS0 = 0; | |
TMR0 = 6; // preset for timer register | |
// Interrupt Registers | |
INTCON = 0; // clear the interrpt control register | |
INTCONbits.TMR0IE = 1; // bit5 TMR0 Overflow Interrupt Enable bit...1 = Enables the TMR0 interrupt | |
INTCONbits.TMR0IF = 0; // bit2 clear timer 0 interrupt flag | |
INTCONbits.GIE = 1; // bit7 global interrupt enable | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment