Advertisement
Guest User

Untitled

a guest
Apr 28th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. /* Main.c file generated by New Project wizard
  2. *
  3. * Created: ju. abr. 7 2016
  4. * Processor: PIC18F4550
  5. * Compiler: MPLAB XC8
  6. */
  7.  
  8. #include <xc.h>
  9. #include "config.h"
  10. #include "ascii.h"
  11. #include<p18f4550.h>
  12. #include "GLCD.h"
  13. #include <math.h>
  14. #include <string.h>
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22. long long int freq = 0;
  23. long long int ticks = 0;
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31. void writeTxt(byte page, byte y, char * text) {
  32. int m=0;
  33. while(text[m]!='\0'){
  34. char k = text[m];
  35. int n= (k-32)*5;
  36. for(int i =0; i<5;++i){
  37. writeByte(page, y+i,font5x7[n+i]);
  38. }
  39. y=y+5;
  40. if (y>128) {y=y-128; ++page;}
  41. ++m;
  42. }
  43. }
  44.  
  45.  
  46. void putch(byte page,byte y,char c){
  47. int n = (c - 32)* 5;
  48. for (int i = 0; i < 5; ++i){
  49. writeByte(page, y+i,font5x7[n+i]);
  50.  
  51.  
  52. }
  53. }
  54.  
  55.  
  56.  
  57. writeNum(byte page, byte y, int valor){
  58. int val = valor;
  59. int i=valor;
  60. int cont = 0;
  61. while (i>9){
  62. ++cont;
  63. i = i/10;
  64. }
  65. cont = cont * 6;
  66. int n = valor%10 + 48;
  67. putch(page,y+cont,n);
  68. valor = valor/10;
  69. cont = cont - 6;
  70.  
  71. while (valor > 9){
  72. if (valor == 10){
  73. putch(page,y+cont,48);
  74. valor = valor/10;
  75. }
  76. else{
  77. putch(page,y+cont,valor%10+48);
  78. valor = valor/10;
  79. }
  80. cont = cont - 6;
  81. }
  82. if (val > 9){
  83. putch(page,y+cont+cont,valor%10+48);
  84. }
  85.  
  86.  
  87.  
  88. }
  89.  
  90.  
  91. void interrupt high_priority timer3_interrupt(){
  92. if (TMR3IE && TMR3IF) {
  93. TMR3IF = 0;
  94. freq = ticks + (TMR3H<<8);
  95. ticks= 0;
  96. TMR3H = 0;
  97. TMR3L = 0;
  98.  
  99. }
  100. return;
  101. }
  102.  
  103. void interrupt low_priority ccp1_interrupt(){
  104. ticks += 0xFFFF;
  105. return;
  106. }
  107.  
  108.  
  109.  
  110.  
  111.  
  112. void main(void){
  113. TRISC = 0x0F;
  114. TMR3CS = 0;
  115. TMR3IF = 0; //Clear flag
  116. TMR3IE = 1; //Enable interrupt TIMER0
  117. TMR3IP = 1; //High priority
  118. RCONbits.IPEN = 1; //Enable priority interrupts
  119. T3CON = 0b11001101;
  120. INTCONbits.GIE = 1; //Enable global interrupts
  121. INTCONbits.GIEH = 1; // Enable high priority interrupts
  122. INTCONbits.GIEL = 1; // Enable low priority interrupts
  123.  
  124. /* Inicialitzacio GLCD */
  125. GLCDinit();
  126. clearGLCD(0,8,0,128);
  127. while (1){
  128. writeTxt(2,30,"Frec:");
  129. writeNum(2,90,freq);
  130. writeTxt(5,30,"Ticks:");
  131. writeNum(5,90,ticks);
  132.  
  133. }
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement