NEED SAMPLE CODE for display a 32x32 pixel bitmap ?

Post your requests and ideas on the future development of mikroBasic.
Post Reply
Author
Message
Adam
Posts: 38
Joined: 18 Sep 2008 10:21

NEED SAMPLE CODE for display a 32x32 pixel bitmap ?

#1 Post by Adam » 04 Oct 2008 02:24

In MikroBasic for AVR , using GLCD library , how to draw a specified bitmap such as 32x32 pixel like this ? PLease help me !!! ( something like T6963C_sprite sub routine)

const mybitmap as byte[128] = (0x00, 0x00, 0x80, 0xE0, 0xF0, 0x78, 0x38, 0x3C, 0xBC, 0xB8, 0xF0, 0xE0, 0xC0, 0x80, 0xE0, 0xE0,
0x20, 0x00, 0xFE, 0xC0, 0x00, 0xFE, 0xC6, 0x7C, 0xFE, 0x1E, 0xFE, 0x38, 0xFE, 0xE6, 0xF6, 0x00,
0x00, 0xFC, 0x1F, 0x03, 0xF2, 0xFE, 0xFE, 0xCE, 0x0E, 0xFF, 0xFE, 0xFD, 0x3F, 0xFF, 0xE3, 0x00,
0x18, 0xF8, 0x08, 0xF8, 0xF8, 0x78, 0xF8, 0x08, 0x18, 0xF8, 0x08, 0xF8, 0xF8, 0x70, 0xF8, 0x00,
0x00, 0x0F, 0xFC, 0xFF, 0xFF, 0xE3, 0xE1, 0xEC, 0xEF, 0xA7, 0xCF, 0xCF, 0xE4, 0xBF, 0x1F, 0x00,
0x60, 0x23, 0x20, 0x03, 0xE3, 0x80, 0xE3, 0xE0, 0x00, 0xE3, 0xA0, 0xE3, 0xC3, 0xE0, 0xE3, 0x00,
0x00, 0x00, 0x07, 0x0A, 0x13, 0x15, 0x11, 0x23, 0x43, 0x21, 0x19, 0x13, 0x09, 0x7F, 0x70, 0x60,
0x70, 0x41, 0xB1, 0x60, 0x01, 0x71, 0x30, 0x61, 0x20, 0x71, 0x71, 0x71, 0x60, 0x61, 0x71, 0x60 )

rmteo
Posts: 1330
Joined: 19 Oct 2006 17:46
Location: Colorado, USA

#2 Post by rmteo » 04 Oct 2008 07:46

I'm not sure about mB for AVR but with mB for PIC, the GLCD library allows you to write a data byte a specific loacation:
Prototype sub procedure Glcd_Write_Data(dim data as byte)
Returns Nothing.
Description Writes data to the current location in GLCD memory and moves to the next location.
Use the functions Glcd_Set_Side, Glcd_Set_X, and Glcd_Set_Page to specify an exact position on GLCD. Then, you can use Glcd_Write_Data or Glcd_Read_Data on that location.
Requires GLCD needs to be initialized. See Glcd_Init.
Example Glcd_Write_Data(data)
Why pay for overpriced toys when you can have
professional grade tools for FREE!!! :D :D :D

Adam
Posts: 38
Joined: 18 Sep 2008 10:21

#3 Post by Adam » 04 Oct 2008 12:21

I used glcd_write_data , this is my code :

program GlcdTest
const mybitmap as byte[128] = (0 ,0 ,0 ,0 ,0 ,0 ,0 ,0,
0 ,128 ,192 ,224 ,240 ,248 ,248 ,252,
124 ,126 ,62 ,62 ,62 ,62 ,126 ,254,
254 ,254 ,252 ,252 ,248 ,240 ,0 ,0,
0 ,0 ,0 ,0 ,0 ,0 ,0 ,0,
62 ,127 ,255 ,255 ,255 ,255 ,255 ,253,
240 ,240 ,224 ,224 ,240 ,248 ,254 ,191,
63 ,31 ,31 ,15 ,7 ,1 ,0 ,0,
0 ,0 ,0 ,224 ,240 ,248 ,252 ,254,
254 ,255 ,31 ,7 ,3 ,1 ,3 ,3,
7 ,7 ,143 ,255 ,255 ,255 ,255 ,255,
255 ,126 ,0 ,0 ,0 ,0 ,0 ,0,
0 ,0 ,3 ,15 ,31 ,63 ,63 ,127,
127 ,127 ,126 ,124 ,124 ,124 ,124 ,124,
62 ,62 ,63 ,31 ,31 ,15 ,7 ,3,
1 ,0 ,0 ,0 ,0 ,0 ,0 ,0
)

Dim i,j as byte

sub procedure drawbitmap1 'draw mybitmap at first location at x=64 , page =4
j=4
glcd_set_x(64)
glcd_set_page(j)
for i=0 to 127
dataR=glcd_read_data()
dataR=dataR and s8
glcd_write_data(dataR)
if (i+1) mod 32=0 then
j=j+1
glcd_set_page(j)
glcd_set_x(64)
end if
next i
end sub

sub procedure drawbitmap2 ' 'draw mybitmap at second location at x=96 , page =4

j=4
glcd_set_x(96)
glcd_set_page(j)
for i=0 to 127
dataR=glcd_read_data()
dataR=dataR and s8
glcd_write_data(dataR)
if (i+1) mod 32=0 then
j=j+1
glcd_set_page(j)
glcd_set_x(96)
end if
next i
end sub

sub procedure drawbitmap3 ' 'draw mybitmap at second location at x=0 , page =0

j=0
glcd_set_x(0)
glcd_set_page(j)
for i=0 to 127
dataR=glcd_read_data()
dataR=dataR and s8
glcd_write_data(dataR)
if (i+1) mod 32=0 then
j=j+1
glcd_set_page(j)
glcd_set_x(0)
end if
next i
end sub


main:

Glcd_Init(PORTA, 0,1,2, 3, 4, 5, PORTD)

drawbitmap1
drawbitmap2
drawbitmap3

end.


The error that I get is I am just able to use draw 2 of 3 sub procedure to draw bitmap as the same time ( example : just drawbitmap1 and drawbitmap2 , or drawbitmap1 and drawbitmap3 , or drawbitmap2 and drawbitmap3 )


I can't used 3 sub procedure at the same time . The error I get is the LCD display nothing or garbage character . What's wrong ?? ???? ( I used ATMEGA32 and GLCD KS0108)

Adam
Posts: 38
Joined: 18 Sep 2008 10:21

#4 Post by Adam » 04 Oct 2008 12:26

Sorry , I don't know how to edit my last post . Need repplace "s8" with "mybitmap"

Adam
Posts: 38
Joined: 18 Sep 2008 10:21

#5 Post by Adam » 04 Oct 2008 12:28

I used glcd_write_data , this is my code :

program GlcdTest
const mybitmap as byte[128] = (0 ,0 ,0 ,0 ,0 ,0 ,0 ,0,
0 ,128 ,192 ,224 ,240 ,248 ,248 ,252,
124 ,126 ,62 ,62 ,62 ,62 ,126 ,254,
254 ,254 ,252 ,252 ,248 ,240 ,0 ,0,
0 ,0 ,0 ,0 ,0 ,0 ,0 ,0,
62 ,127 ,255 ,255 ,255 ,255 ,255 ,253,
240 ,240 ,224 ,224 ,240 ,248 ,254 ,191,
63 ,31 ,31 ,15 ,7 ,1 ,0 ,0,
0 ,0 ,0 ,224 ,240 ,248 ,252 ,254,
254 ,255 ,31 ,7 ,3 ,1 ,3 ,3,
7 ,7 ,143 ,255 ,255 ,255 ,255 ,255,
255 ,126 ,0 ,0 ,0 ,0 ,0 ,0,
0 ,0 ,3 ,15 ,31 ,63 ,63 ,127,
127 ,127 ,126 ,124 ,124 ,124 ,124 ,124,
62 ,62 ,63 ,31 ,31 ,15 ,7 ,3,
1 ,0 ,0 ,0 ,0 ,0 ,0 ,0
)

Dim i,j as byte

sub procedure drawbitmap1 'draw mybitmap at first location at x=64 , page =4
j=4
glcd_set_x(64)
glcd_set_page(j)
for i=0 to 127

glcd_write_data(mybitmap)
if (i+1) mod 32=0 then
j=j+1
glcd_set_page(j)
glcd_set_x(64)
end if
next i
end sub

sub procedure drawbitmap2 ' 'draw mybitmap at second location at x=96 , page =4

j=4
glcd_set_x(96)
glcd_set_page(j)
for i=0 to 127
glcd_write_data(mybitmap)
if (i+1) mod 32=0 then
j=j+1
glcd_set_page(j)
glcd_set_x(96)
end if
next i
end sub

sub procedure drawbitmap3 ' 'draw mybitmap at second location at x=0 , page =0

j=0
glcd_set_x(0)
glcd_set_page(j)
for i=0 to 127
glcd_write_data(mybitmap)
if (i+1) mod 32=0 then
j=j+1
glcd_set_page(j)
glcd_set_x(0)
end if
next i
end sub


main:

Glcd_Init(PORTA, 0,1,2, 3, 4, 5, PORTD)

drawbitmap1
drawbitmap2
drawbitmap3

end.


The error that I get is I am just able to use draw 2 of 3 sub procedure to draw bitmap as the same time ( example : just drawbitmap1 and drawbitmap2 , or drawbitmap1 and drawbitmap3 , or drawbitmap2 and drawbitmap3 )


I can't used 3 sub procedure at the same time . The error I get is the LCD display nothing or garbage character . What's wrong ?? ???? ( I used ATMEGA32 and GLCD KS0108)

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

#6 Post by janni » 04 Oct 2008 13:20

You should read data from GLCD twice (with glcd_read_data()) as the first read moves data byte from GLCD memory to a buffer, and only the second one moves data from buffer to data lines. Like

Code: Select all

  glcd_read_data() 
  dataR=glcd_read_data() 
You should also use the GLCD_Set_Side routine. And, as every read or write increases x position of internal GLCD counter, you should set x again between read and write.

Adam
Posts: 38
Joined: 18 Sep 2008 10:21

#7 Post by Adam » 04 Oct 2008 14:02

Thank you , but can you post the sample code ( full code edit from my code ? )

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

#8 Post by janni » 04 Oct 2008 16:29

I'm sorry but no. We only help here, you're supposed to do the main work.

You have enough information now to do it yourself with very little effort. (Not that you couldn't read the KS108 datasheet by yourself :wink: )

Adam
Posts: 38
Joined: 18 Sep 2008 10:21

#9 Post by Adam » 05 Oct 2008 02:58

Here is new result I get from Proteus Simulator
Image

program xGlcdTest
const mybitmap as byte[128]=(0 ,0 ,0 ,0 ,0 ,0 ,0 ,0,
0 ,0 ,0 ,0 ,128 ,128 ,224 ,240,
240 ,0 ,0 ,0 ,0 ,0 ,0 ,0,
0 ,0 ,0 ,0 ,0 ,0 ,0 ,0,
0 ,0 ,0 ,0 ,0 ,0 ,0 ,0,
0 ,7 ,7 ,7 ,7 ,7 ,255 ,255,
255 ,0 ,0 ,0 ,0 ,0 ,0 ,0,
0 ,0 ,0 ,0 ,0 ,0 ,0 ,0,
0 ,0 ,0 ,0 ,0 ,0 ,0 ,0,
0 ,0 ,0 ,0 ,0 ,0 ,255 ,255,
255 ,0 ,0 ,0 ,0 ,0 ,0 ,0,
0 ,0 ,0 ,0 ,0 ,0 ,0 ,0,
0 ,0 ,0 ,0 ,0 ,0 ,0 ,0,
0 ,28 ,28 ,28 ,28 ,28 ,31 ,31,
31 ,28 ,28 ,28 ,28 ,28 ,0 ,0,
0 ,0 ,0 ,0 ,0 ,0 ,0 ,0)

dim i,j,DATAR as byte


sub procedure mybitmap_1 'draw mybitmap at first location at x=64 , page =4
j=4
glcd_set_x(64)
glcd_set_page(j)
for i=0 to 127
dataR=glcd_read_data()
dataR=dataR or mybitmap
glcd_write_data(dataR)
if (i+1) mod 32=0 then
j=j+1
glcd_set_page(j)
glcd_set_x(64)
end if
next i
end sub
sub procedure mybitmap_2 'draw mybitmap at second location at x=96 , page =4

j=4
glcd_set_x(96)
glcd_set_page(j)
for i=0 to 127

dataR=glcd_read_data()

dataR=dataR or mybitmap

glcd_write_data(dataR)
if (i+1) mod 32=0 then
j=j+1
glcd_set_page(j)
glcd_set_x(96)
end if
next i
end sub
sub procedure mybitmap_3 'draw mybitmap at 3rd location at x=0 , page =0
j=0
glcd_set_x(0)
glcd_set_page(j)
for i=0 to 127
dataR=glcd_read_data()
dataR=dataR or mybitmap
glcd_write_data(dataR)
if (i+1) mod 32=0 then
j=j+1
glcd_set_page(j)
glcd_set_x(0)
end if
next i
end sub
sub procedure mybitmap_4 'draw mybitmap at 4th location at x=32 , page =4

j=4
glcd_set_x(32)
glcd_set_page(j)
for i=0 to 127
dataR=glcd_read_data()
dataR=dataR or mybitmap
glcd_write_data(dataR)
if (i+1) mod 32=0 then
j=j+1
glcd_set_page(j)
glcd_set_x(32)
end if
next i
end sub
sub procedure mybitmap_5 'draw mybitmap at 5th location at x=32 , page =0

j=0
glcd_set_x(32)
glcd_set_page(j)
for i=0 to 127
dataR=glcd_read_data()
dataR=dataR or mybitmap
glcd_write_data(dataR)
if (i+1) mod 32=0 then
j=j+1
glcd_set_page(j)
glcd_set_x(32)
end if
next i
end sub

main:
Glcd_Init(PORTC, 2, 1, 3, 4, 5, 0, PORTA) 'Good only for EasyPic3
Glcd_Set_Font(font5x8, 5, 8, 32)
glcd_fill(0)
mybitmap_1
mybitmap_2
mybitmap_3
mybitmap_4
mybitmap_5

end.
[/img]

Post Reply

Return to “mikroBasic Wish List”