Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // **************************************************************************
- //
- // Demo program for labs
- //
- // Subject: Computer Architectures and Parallel systems
- // Author: Petr Olivka, petr.olivka@vsb.cz, 08/2016
- // Organization: Department of Computer Science, FEECS,
- // VSB-Technical University of Ostrava, CZ
- //
- // File: Main program for LCD module
- //
- // **************************************************************************
- #include "mbed.h"
- #include <string>
- Serial pc( USBTX, USBRX );
- #include "lcd_lib.h"
- // two dimensional array with fixed size font
- extern uint8_t font8x8[ 256 ][ 8 ];
- class point{
- private:
- int x;
- int y;
- int color;
- public :
- void setXY(int x, int y)
- {
- this->x = x;
- this->y = y;
- }
- void setColor(uint8_t r,uint8_t g, uint8_t b)
- {
- r>>=3;
- g>>=2;
- b>>=3;
- color = 0x0;
- color +=r;
- color <<= 6;
- color+=g;
- color <<= 5;
- color+=b;
- }
- virtual void view()
- {
- LCD_put_pixel(this->x,this->y,this->color);
- }
- };
- void print_char(int startX, int startY, char znak, int color)
- {
- for(int y = 0; y < 8; y++)
- {
- for(int x = 0; x < 8; x++)
- {
- if(font8x8[(int)znak][y] & (1<<x))
- {
- LCD_put_pixel(startX + x, startY + y, color);
- }
- }
- }
- }
- void print_string(int startX, int startY,string retezec, int color)
- {
- for(unsigned int i = 0; i < retezec.length(); i++)
- {
- print_char(startX, startY, retezec[i], color);
- startX +=9;
- if(startX >= 320)
- {
- startX = 0;
- startY +=10;
- }
- }
- }
- struct cas{
- int h;
- int m;
- int s;
- };
- void cas_init(cas *pcas)
- {
- pcas->h = 0;
- pcas->m = 0;
- pcas->s = 0;
- }
- void cas_inc(cas *pcas)
- {
- if(pcas->s < 59)
- pcas->s += 1;
- else
- {
- pcas->s = 0;
- if(pcas->m < 59)
- pcas->m += 1;
- else
- {
- pcas->m = 0;
- if(pcas->h < 23)
- pcas->h = 0;
- }
- }
- }
- void cas2str(cas *pcas,char *str)
- {
- sprintf(str,"%02d:%02d:%02d",pcas->h,pcas->m,pcas->s);
- }
- int main()
- {
- LCD_init(); // LCD initialization
- LCD_clear(); // LCD clear screen
- int color_red = 0xF800;
- int color_green = 0x07E0;
- int color_blue = 0x001F;
- int color_white = 0xFFFF;
- /*
- // simple animation display four color square using LCD_put_pixel function
- int limit = 200;
- for ( int ofs = 0; ofs < 20; ofs++ ) // square offset in x and y axis
- for ( int i = 0; i < limit; i++ )
- {
- LCD_put_pixel( ofs + i, ofs + 0, color_red );
- LCD_put_pixel( ofs + 0, ofs + i, color_green );
- LCD_put_pixel( ofs + i, ofs + limit, color_blue );
- LCD_put_pixel( ofs + limit, ofs + i, color_white );
- }
- return 0;
- for(int i=0;i<240;i++)
- for(int j=0;j<320;j++)
- {
- point p;
- p.setXY(j,i);
- if(j<100)
- p.setColor(255,0,0);
- if(j>100&&j<200)
- p.setColor(0,255,0);
- if(j>200)
- p.setColor(0,0,255);
- p.view();
- }
- */
- bool start = false;
- bool stop = false;
- bool stop2 = false;
- DigitalIn but9( PTC9 );
- DigitalIn but10( PTC10 );
- DigitalIn but11( PTC11 );
- DigitalIn but12( PTC12 );
- char pole[14];
- char pole2[14];
- cas casovac;
- cas casovac2;
- cas_init(&casovac);
- while(1)
- {
- if(start)
- {
- print_string(20,20,pole,0x0);
- cas2str(&casovac,pole);
- cas_inc(&casovac);
- print_string(20,20,pole,color_white);
- wait_ms(1000);
- }
- if(!but12)
- {
- print_string(20,20,pole,0x0);
- cas_init(&casovac);
- cas2str(&casovac,pole);
- print_string(20,20,pole,color_white);
- wait_ms(100);
- }
- if(!but9)
- {
- start = true;
- stop=false;
- wait_ms(100);
- }
- if(!but10)
- {
- stop = true;
- start=false;
- wait_ms(100);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement