Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <xc.h>
- #define _XTAL_FREQ 8000000 // Need for __delay_ms function
- #include <stdlib.h>
- // Need for ... just check yourself
- #include <string.h>
- // Need for string manipulation
- #include "config.h"
- #include "GLCD.h"
- #include "ascii.h"
- #include <math.h>
- #include "Bart.h"
- byte Ax,By,Gpage;
- void
- SetDot(byte x, byte y)
- { // Turn on pixel (x,y)
- byte select_led=0x01<<x%8;
- byte aux=readByte(x/8,y);
- byte vector_a_guardar=select_led|aux;
- writeByte(x/8,y,vector_a_guardar);
- }
- void ClearDot(byte x, byte y) {
- // Turn off pixel (x,y)
- byte select_led=0x01<<x%8;
- select_led=~select_led;
- byte aux=readByte(x/8,y);
- byte vector_a_guardar=select_led&aux;
- writeByte(x/8,y,vector_a_guardar);}
- void putch(byte page,byte y,char c) {
- int table=c-32;
- table=table*5;
- for(int i=0;i<5;++i){
- writeByte(page,y+i,font5x7[table+i]);
- }
- // Write character βcβ (ASCII CODE) on
- }
- // position page, column y
- void
- writeTxt(byte page, byte y, char* text) { int i=0;
- int checker;
- int amount;
- int written=1;
- while(text[i]!='\0'){
- if(text[i]=='\n') {page+=1;
- y=0;}
- else{
- if(written){
- checker=i;
- amount=0;
- while(text[checker]!=' ' && text[checker]!='\0'){
- checker+=1;
- amount+=5;
- written=0;}
- }
- if (amount>125){
- while(text[i]!=' '&&text[i]!='\0'){
- if(y>=125){page+=1;
- y=0;}
- putch(page,y,text[i]);
- ++i;
- y+=5;}
- written=1;
- }
- else if (amount<=125){
- int suma=y+amount;
- if((suma)>=125){page+=1;
- y=0;}
- if(text[i]==' '){
- ++i;
- y+=5;
- if(y>=125){ y=0;page+=1;}
- written=1;
- }
- else {
- while(text[i]!=' '&&text[i]!='\0'){
- putch(page,y,text[i]);
- ++i;
- y+=5;
- }
- written=1;}
- }
- }
- }
- }
- // Write string on GLCD
- void writeNum(byte page, byte y, int valor)
- {
- int copia=valor;
- char converted[200];
- itoa(converted,valor,10);
- int n=0;
- do {
- copia/=10;
- ++n;
- } while(copia);
- int i=0;
- for(i=0; i<n;++i){
- putch(page,y,converted[i]);
- y+=5;
- if(y>=125){page+=1;y=0;}
- }
- if(valor<0){
- putch(page,y,converted[i]);
- }
- }
- // Write an interger value on GLCD
- void
- moveDot(){
- // Move a dot on the screen.
- SetDot(Ax,By);
- ClearDot(Ax,By);
- By=By+1;
- if(By==128)By=0;
- }
- void
- info(){
- // Write group names,lab code and date
- Ax=By=Gpage=0;
- writeTxt(0,0,"Javier,BerniNOOB,Guille Grup: 31? no se xd la C segur, dia 26/10/2016 javi puto amo");
- }
- void image(){
- // Write the image at bitmap array on the screen
- int i,j;
- for(i = 0; i < 8; i++)
- for(j = 0; j < 128; j++)
- writeByte(i,j,bitmap[i*128+j]);
- }
- void InitPIC () {
- // Initialize PORTβs and basic PIC resources
- }
- void main(void) {
- InitPIC();
- GLCDinit();
- // GLCD routines are in rutines_GLCD.C
- clearGLCD(0, 7, 0, 127);
- setStartLine(0);
- // MAIN LOOP
- while (1) {
- image();
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement