Advertisement
Guest User

este omar

a guest
Oct 27th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1.  
  2. #include <xc.h>
  3. #define _XTAL_FREQ 8000000 // Need for __delay_ms function
  4. #include <stdlib.h>
  5. // Need for ... just check yourself
  6. #include <string.h>
  7. // Need for string manipulation
  8. #include "config.h"
  9. #include "GLCD.h"
  10. #include "ascii.h"
  11. #include <math.h>
  12. #include "Bart.h"
  13. byte Ax,By,Gpage;
  14. void
  15. SetDot(byte x, byte y)
  16. { // Turn on pixel (x,y)
  17. byte select_led=0x01<<x%8;
  18. byte aux=readByte(x/8,y);
  19. byte vector_a_guardar=select_led|aux;
  20. writeByte(x/8,y,vector_a_guardar);
  21.  
  22. }
  23. void ClearDot(byte x, byte y) {
  24. // Turn off pixel (x,y)
  25. byte select_led=0x01<<x%8;
  26. select_led=~select_led;
  27. byte aux=readByte(x/8,y);
  28. byte vector_a_guardar=select_led&aux;
  29. writeByte(x/8,y,vector_a_guardar);}
  30.  
  31. void putch(byte page,byte y,char c) {
  32. int table=c-32;
  33. table=table*5;
  34. for(int i=0;i<5;++i){
  35. writeByte(page,y+i,font5x7[table+i]);
  36. }
  37.  
  38. // Write character β€˜c’ (ASCII CODE) on
  39. }
  40. // position page, column y
  41. void
  42. writeTxt(byte page, byte y, char* text) { int i=0;
  43. int checker;
  44. int amount;
  45. int written=1;
  46. while(text[i]!='\0'){
  47. if(text[i]=='\n') {page+=1;
  48. y=0;}
  49. else{
  50. if(written){
  51. checker=i;
  52. amount=0;
  53. while(text[checker]!=' ' && text[checker]!='\0'){
  54. checker+=1;
  55. amount+=5;
  56. written=0;}
  57. }
  58. if (amount>125){
  59. while(text[i]!=' '&&text[i]!='\0'){
  60. if(y>=125){page+=1;
  61. y=0;}
  62. putch(page,y,text[i]);
  63. ++i;
  64. y+=5;}
  65. written=1;
  66. }
  67. else if (amount<=125){
  68. int suma=y+amount;
  69. if((suma)>=125){page+=1;
  70. y=0;}
  71. if(text[i]==' '){
  72. ++i;
  73. y+=5;
  74. if(y>=125){ y=0;page+=1;}
  75. written=1;
  76. }
  77.  
  78. else {
  79. while(text[i]!=' '&&text[i]!='\0'){
  80. putch(page,y,text[i]);
  81. ++i;
  82. y+=5;
  83.  
  84. }
  85. written=1;}
  86. }
  87. }
  88. }
  89. }
  90. // Write string on GLCD
  91. void writeNum(byte page, byte y, int valor)
  92. {
  93.  
  94. int copia=valor;
  95. char converted[200];
  96. itoa(converted,valor,10);
  97. int n=0;
  98. do {
  99. copia/=10;
  100. ++n;
  101. } while(copia);
  102. int i=0;
  103. for(i=0; i<n;++i){
  104. putch(page,y,converted[i]);
  105. y+=5;
  106. if(y>=125){page+=1;y=0;}
  107. }
  108. if(valor<0){
  109. putch(page,y,converted[i]);
  110. }
  111. }
  112. // Write an interger value on GLCD
  113. void
  114.  
  115. moveDot(){
  116. // Move a dot on the screen.
  117. SetDot(Ax,By);
  118. ClearDot(Ax,By);
  119. By=By+1;
  120. if(By==128)By=0;
  121. }
  122. void
  123. info(){
  124. // Write group names,lab code and date
  125. Ax=By=Gpage=0;
  126. writeTxt(0,0,"Javier,BerniNOOB,Guille Grup: 31? no se xd la C segur, dia 26/10/2016 javi puto amo");
  127.  
  128.  
  129. }
  130. void image(){
  131. // Write the image at bitmap array on the screen
  132. int i,j;
  133. for(i = 0; i < 8; i++)
  134. for(j = 0; j < 128; j++)
  135. writeByte(i,j,bitmap[i*128+j]);
  136. }
  137. void InitPIC () {
  138. // Initialize PORT’s and basic PIC resources
  139.  
  140. }
  141. void main(void) {
  142.  
  143. InitPIC();
  144. GLCDinit();
  145. // GLCD routines are in rutines_GLCD.C
  146. clearGLCD(0, 7, 0, 127);
  147. setStartLine(0);
  148.  
  149. // MAIN LOOP
  150. while (1) {
  151.  
  152. image();
  153.  
  154. };
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement