Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Main.c file generated by New Project wizard
- *
- * Created: ju. abr. 7 2016
- * Processor: PIC18F4550
- * Compiler: MPLAB XC8
- */
- #include <xc.h>
- #include "config.h"
- #include "ascii.h"
- #include<p18f4550.h>
- #include "GLCD.h"
- #include <math.h>
- #include <string.h>
- long long int freq = 0;
- long long int ticks = 0;
- void writeTxt(byte page, byte y, char * text) {
- int m=0;
- while(text[m]!='\0'){
- char k = text[m];
- int n= (k-32)*5;
- for(int i =0; i<5;++i){
- writeByte(page, y+i,font5x7[n+i]);
- }
- y=y+5;
- if (y>128) {y=y-128; ++page;}
- ++m;
- }
- }
- void putch(byte page,byte y,char c){
- int n = (c - 32)* 5;
- for (int i = 0; i < 5; ++i){
- writeByte(page, y+i,font5x7[n+i]);
- }
- }
- writeNum(byte page, byte y, int valor){
- int val = valor;
- int i=valor;
- int cont = 0;
- while (i>9){
- ++cont;
- i = i/10;
- }
- cont = cont * 6;
- int n = valor%10 + 48;
- putch(page,y+cont,n);
- valor = valor/10;
- cont = cont - 6;
- while (valor > 9){
- if (valor == 10){
- putch(page,y+cont,48);
- valor = valor/10;
- }
- else{
- putch(page,y+cont,valor%10+48);
- valor = valor/10;
- }
- cont = cont - 6;
- }
- if (val > 9){
- putch(page,y+cont+cont,valor%10+48);
- }
- }
- void interrupt high_priority timer3_interrupt(){
- if (TMR3IE && TMR3IF) {
- TMR3IF = 0;
- freq = ticks + (TMR3H<<8);
- ticks= 0;
- TMR3H = 0;
- TMR3L = 0;
- }
- return;
- }
- void interrupt low_priority ccp1_interrupt(){
- ticks += 0xFFFF;
- return;
- }
- void main(void){
- TRISC = 0x0F;
- TMR3CS = 0;
- TMR3IF = 0; //Clear flag
- TMR3IE = 1; //Enable interrupt TIMER0
- TMR3IP = 1; //High priority
- RCONbits.IPEN = 1; //Enable priority interrupts
- T3CON = 0b11001101;
- INTCONbits.GIE = 1; //Enable global interrupts
- INTCONbits.GIEH = 1; // Enable high priority interrupts
- INTCONbits.GIEL = 1; // Enable low priority interrupts
- /* Inicialitzacio GLCD */
- GLCDinit();
- clearGLCD(0,8,0,128);
- while (1){
- writeTxt(2,30,"Frec:");
- writeNum(2,90,freq);
- writeTxt(5,30,"Ticks:");
- writeNum(5,90,ticks);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement