Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 09:16 08 Jul 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : uM2(+): The impossible takes a bit longer

     Page 1 of 2    
Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10223
Posted: 12:10am 10 Apr 2016
Copy link to clipboard 
Print this post

lew247 has a habit of asking for things that are very easy to describe but excruciatingly difficult to find a solution and code.

See this as an example.





The code is running on a 64-pin Micromite+ and using Geoff's standard firmware driver for a 800x480 SSD1963 display. To use the code the RD pin on the display must be connected and set up in the firmware using this simple call

sub mm.startup
setrd(30)' set up the read pin
end sub

Csub setrd
00000000
27BDFFE8 AFBF0014 AFB00010 3C109D00 8C830000 8E020090 24050008 00003021
A043002D 8E030090 8E020010 0040F809 8064002D 8E030090 8E020010 24050065
8064002D 0040F809 00003021 8E030090 8E02001C 24050006 0040F809 8064002D
8FBF0014 8FB00010 03E00008 27BD0018
End Csub


The clever bit is a new CFunction that reads one or more triangular shapes off the display into a buffer and then can write one or more single colour triangles back onto the display.

Why triangles? Because they are the easy way to display a rectangle rotated by other than multiples of 90 degrees. A rectangle can be considered as two triangles by splitting it along one of the diagonals. Using simple trigonometry we can rotate the points making up the triangle about an arbitrary point and then we can then use the "fill triangle" routine to display it on the screen.

The clock program uses two triangles for the second hand and one each for the minute and hour hands. Of course, the technique is infinitely expandable to any number of triangles and not limited to "clocks".

The key calls in the program are:

if first then
i=triangles(nt, buff() , tcol(nt), xx0(nt), yy0(nt), xx1(nt), yy1(nt), xx2(nt), yy2(nt))
print "Read buffer is ",i/buffersize*100,"% used"
first=0
else
i=triangles(nt*2, buff() , tcol(), xx0(), yy0(), xx1(), yy1(), xx2(), yy2())
endif


The first time into the code the CFunction is called to read in the background where the first triangles are to be written and write out the required number of triangles (nt). The background is read into the array "buff". It does this when the colour for the triangle is specified.

Subsequently, the same call is used but with twice the number of triangles. In this case the first set have the colour set to -1. This tells the CFunction to write out the triangles using whatever is stored in "buff" and you will see in the rest of the program the coordinates of the first set of triangles are those previously displayed. This restores the background to its original status. The the new triangles are then drawn but as before their background is read and stored before they are displayed.

As the CFunction does all the difficult work the complete program is pretty simple.

The C source is attached:

2016-04-10_100726_Triangles.zip

as is the .BMP used in the example code:

2016-04-10_100905_bigben.zip



option explicit
option default none
const buffersize = 2500
dim integer buff(buffersize)
dim integer nt=4 'Number of triangles being updated
dim integer xx0(nt*2-1),yy0(nt*2-1),xx1(nt*2-1),yy1(nt*2-1),xx2(nt*2-1),yy2(nt*2-1),tcol(nt*2-1),secs,mins,hours,first=1
cls
load image "bigben.bmp",160,0
Circle MM.Hres\2, MM.Vres\2, (MM.Vres\2-MM.Vres\12)\12, 0, , rgb(red), rgb(red))
Circle MM.Hres\2, MM.Vres\2, (MM.Vres\2-MM.Vres\12)\15, 0, , 0, 0
Circle MM.Hres\2, MM.Vres\2, (MM.Vres\2-MM.Vres\12)\20, 0, , RGB(gray), RGB(gray)
secs=val(right$(time$,2))
mins=val(mid$(time$,4,2))
hours=val(left$(time$,2))
do
hands(secs,mins,hours,(MM.Vres\2-MM.Vres\12),MM.Hres\2, MM.Vres\2)
secs = (secs + 1) mod 60
if secs=0 then mins = (mins+1) mod 60
if hours=0 then hours = (hours+1) mod 12
pause 1000
loop
end
'
Sub hands(seconds As integer, minutes as integer, hours as integer, size as integer, x as integer, y as integer)
Local integer x1,y1,x2,y2,x0,y0,i
local float angle=seconds*6
rotatetriangle(2,RGB(RED),angle,x,y,-3,50,3,50,-3,-size) 'make up the second hand with two triangles
rotatetriangle(3,RGB(RED),angle,x,y,3,-size,3,50,-3,-size)
angle=minutes*6 + seconds/10
rotatetriangle(0,RGB(BLACK),angle,x,y,-size/15,0,size/15,0,0,-size*0.8)
angle=hours*30 + minutes/2
rotatetriangle(1,RGB(BLACK),angle,x,y,-size/12,0,size/12,0,0,-size*0.5)
if first then
i=triangles(nt, buff() , tcol(nt), xx0(nt), yy0(nt), xx1(nt), yy1(nt), xx2(nt), yy2(nt))
print "Read buffer is ",i/buffersize*100,"% used"
first=0
else
i=triangles(nt*2, buff() , tcol(), xx0(), yy0(), xx1(), yy1(), xx2(), yy2())
endif
Circle x,y, size\12, 0, , rgb(red), rgb(red))
Circle x,y, size\15, 0, , 0, 0
Circle x,y, size\20, 0, , RGB(gray), RGB(gray)
End Sub

sub rotatetriangle(n as integer, col as integer, angle as float, x as integer, y as integer, x0 as integer, y0 as integer, x1 as integer, y1 as integer, x2 as integer, y2 as integer)
local float sine=sin(rad(angle)),cosine=cos(rad(angle))
local integer x0a,y0a,x1a,y1a,x2a,y2a
x0a= x0*cosine - y0 * sine + x
y0a= y0*cosine + x0 * sine + y
x1a= x1*cosine - y1 * sine + x
y1a= y1*cosine + x1 * sine + y
x2a= x2*cosine - y2 * sine + x
y2a= y2*cosine + x2 * sine + y
xx0(n)=xx0(n+nt)
yy0(n)=yy0(n+nt)
xx1(n)=xx1(n+nt)
yy1(n)=yy1(n+nt)
xx2(n)=xx2(n+nt)
yy2(n)=yy2(n+nt)
xx0(n+nt)=x0a
yy0(n+nt)=y0a
xx1(n+nt)=x1a
yy1(n+nt)=y1a
xx2(n+nt)=x2a
yy2(n+nt)=y2a
tcol(n)=-1
tcol(n+nt)=col
end sub

sub mm.startup
setrd(30)' set up the read pin
end sub

Csub setrd
00000000
27BDFFE8 AFBF0014 AFB00010 3C109D00 8C830000 8E020090 24050008 00003021
A043002D 8E030090 8E020010 0040F809 8064002D 8E030090 8E020010 24050065
8064002D 0040F809 00003021 8E030090 8E02001C 24050006 0040F809 8064002D
8FBF0014 8FB00010 03E00008 27BD0018
End Csub

CFunction triangles
0000024B
'defineregion
3C029D00 8C480094 8C420098 24091000 3C03BF88 AC696134 8C430000 8D020000
248AFFFF 24A9FFFF 0062402B 01463021 01274821 11000003 00605821 00405821
00601021 3C039D00 8C680090 240C0001 81030015 146C000B 24070002 8102002C
00806821 28420007 14400023 00C06021 00063027 00042027 008B6021 1000001E
00CB6821 14670008 24070003 00063027 00042027 00A06821 01206021 00C22821
10000015 00824821 1467000E 00094827 8103002C 00053827 28630007 01222821
00C06021 00806821 1060000B 00E24821 00063027 00042027 008B6021 10000006
00CB6821 00056027 012B6821 018B6021 00802821 00C04821 000D1202 3C03BF88
24080800 240B1000 000C2202 00057202 00093A02 34421800 2406022A AC666430
35AD1800 AC686134 34841800 AC686138 358C1800 AC6B6138 35CE1800 AC626430
34A51800 34E71800 35291800 2402022B AC686134 AC686138 AC6D6430 AC686134
AC686138 AC646430 AC686134 AC686138 AC6C6430 AC686134 AC686138 AC6B6134
AC626430 AC686134 AC686138 AC6B6138 AC6E6430 AC686134 AC686138 AC656430
AC686134 AC686138 AC676430 AC686134 AC686138 AC696430 AC686134 AC686138
03E00008 00000000
'writeRectangle
27BDFFD8 AFB40020 AFB3001C 00C0A021 00E09821 72749802 AFB00010 8FB00038
AFB20018 AFB10014 00109403 00108A03 AFBF0024 0411FF80 00000000 3C02BF88
24031000 24040800 2405022C AC436134 36521800 AC456430 36311800 AC446134
36101800 AC446138 AC436138 1260000F 2673FFFF 24030800 2404FFFF 2673FFFF
AC526430 AC436134 AC436138 AC516430 AC436134 AC436138 AC506430 AC436134
AC436138 1664FFF6 2673FFFF 8FBF0024 8FB40020 8FB3001C 8FB20018 8FB10014
8FB00010 03E00008 27BD0028
'ReadRectangle
27BDFFC8 AFBF0034 AFBE0030 AFB7002C AFB60028 AFB50024 AFB40020 AFB3001C
AFB20018 3C139D00 AFB10014 AFB00010 8E630090 0080B021 8E620028 8064002D
00C0A821 00E0F021 00A0B821 0040F809 8FB10048 8E640090 8E630024 24050006
8084002D 24100001 0060F809 00508004 8E630090 00409021 8E620024 8064002D
24050005 0040F809 0015A040 0295A021 00409821 729E1002 02C02021 02E02821
02A03021 03C03821 0051A021 0411FF2F 00000000 3C05BF88 24061000 ACA66134
8FA3004C 24070800 2402022E ACA26430 ACA76134 ACA76138 ACA66138 240600FF
00711821 3C02BF81 3C04BF88 ACA6641C AE700000 8C45F220 8C45F220 AE500000
8C866420 26310003 0234282B A0660000 AE700000 8C46F220 8C46F220 AE500000
8C866420 A0660001 AE700000 8C46F220 8C46F220 AE500000 8C866420 A0660002
14A0FFEB 24630003 3C02BF88 240300FF AC43641C 8FBF0034 02201021 8FBE0030
8FB7002C 8FB60028 8FB50024 8FB40020 8FB3001C 8FB20018 8FB10014 8FB00010
03E00008 27BD0038
'RestoreRectangle
27BDFFE0 AFB20018 AFB10014 00C09021 00E08821 72328802 AFB00010 AFBF001C
8FB00030 0411FEEF 00000000 3C02BF88 24031000 24040800 2405022C AC436134
AC456430 AC446134 AC446138 AC436138 1220001D 2631FFFF 8FA40034 02202821
00902021 24030800 2407FFFF 80860000 24A5FFFF 34C61800 AC466430 AC436134
AC436138 80860001 34C61800 AC466430 AC436134 AC436138 80860002 24840003
34C61800 AC466430 AC436134 AC436138 54A7FFEF 80860000 00111040 26100003
00518821 02118021 8FBF001C 02001021 8FB20018 8FB10014 8FB00010 03E00008
27BD0020
'triangles
27BDFFA8 AFB20038 8FA3006C 00809021 8FA40074 AFBE0050 AFB7004C 0083102A
AFB3003C AFB10034 AFBF0054 AFB60048 AFB50044 AFB40040 AFB00030 00A09821
00C0B821 AFA70064 8FB10068 10400006 8FBE007C 02201021 AFA4006C 8FB10070
AFA30074 AFA20070 8FA30074 03C3102A 10400009 8FA6006C 8FA20070 8FA40078
AFBE0074 AFA20078 AFA40070 0060F021 8FA6006C 8FA30074 0066102A 50400008
8FA6006C 8FA40074 02201021 AFA60074 8FB10070 AFA4006C AFA20070 8FA6006C
14DE0036 8FA30074 8FA30070 0071102A 14400006 02203821 0223102A 10400005
8FA40078 10000002 8FA70070 8FB10070 8FA40078 0091102A 54400003 8FB10078
00E4102A 0082380B 1640000C 24020001 8FA5006C 24E70001 02202021 24060001
00F13823 AFB30010 AFB70014 0411FF19 00000000 100000B0 00409821 1642000C
8FA20064 8FA5006C 24E70001 02202021 24060001 00F13823 AFB30010 AFB70014
0411FF6E 00000000 100000A3 00409821 8FA5006C 24E70001 02202021 24060001
00F13823 AFA20010 AFB70014 0411FECE 00000000 10000099 8FBF0054 8FA4006C
007E1026 0002102B 00621023 AFA20020 0044102A 14400044 00808021 8FA60070
8FA20078 00641823 00D13023 00511023 03C42023 AFA60024 AFA20028 0000A021
0000A821 AFA30018 AFA4001C 24160001 8FA40018 8FA6001C 02002821 02A4001A
008001F4 02C03821 00001012 00511021 0286001A 00C001F4 00001812 00711821
0062302A 10C00003 00402021 00601021 00801821 24660001 00402021 16400009
00C23023 02002821 02C03821 AFB30010 AFB70014 0411FECF 00000000 10000012
00409821 5656000C 8FA20064 24630001 00402021 02002821 00623023 02C03821
AFB30010 AFB70014 0411FF24 00000000 10000005 00409821 AFB70014 AFA20010
0411FE89 00000000 8FA30020 8FA40024 8FA60028 26100001 0070102A 02A4A821
1040FFCB 0286A021 03D0102A 1440004A 8FA30070 8FA20078 8FA40074 8FA60078
00431023 AFA20024 8FA2006C 0204A023 00D13023 0202A823 8FA20024 70D5A802
03C41823 8FA4006C AFA60020 AFA30018 03C42023 AFA4001C 24160001 7054A002
8FA40018 8FA6001C 02002821 0284001A 008001F4 8FA40070 02C03821 00001012
00441021 02A6001A 00C001F4 00001812 00711821 0062202A 10800003 00403021
00601021 00C01821 24660001 00402021 16400009 00C23023 02002821 02C03821
AFB30010 AFB70014 0411FE82 00000000 10000012 00409821 5656000C 8FA20064
24630001 00402021 02002821 00623023 02C03821 AFB30010 AFB70014 0411FED7
00000000 10000005 00409821 AFB70014 AFA20010 0411FE3C 00000000 8FA30024
8FA40020 26100001 03D0102A 0283A021 1040FFCB 02A4A821 8FBF0054 02601021
8FBE0050 8FB7004C 8FB60048 8FB50044 8FB40040 8FB3003C 8FB20038 8FB10034
8FB00030 03E00008 27BD0058
'main
27BDFFB0 AFBE0048 AFB70044 AFB60040 AFB5003C AFB40038 AFB1002C AFBF004C
AFB30034 AFB20030 AFB00028 8C820000 00808821 00A0A821 AFA60058 00E0A021
8FBE0068 8FB7006C 1840002B 8FB60070 8CC40004 04800004 8CC70000 00008021
1000009B 00001821 8FB20058 00001821 00001021 00008021 8FA40060 8FA50064
02834821 00834021 00A33021 02E32021 03C32821 02C31821 8D2C0000 8D0B0000
8CCA0000 8CA90000 8C880000 8C630000 24040001 00402821 02A03021 AFA30024
AFAC0010 AFAB0014 AFAA0018 AFA9001C AFA80020 0411FEBF 00000000 8E240000
26100001 0204202A 14800006 001018C0 10000030 00001021 00008021 1000002D
00001021 8E44000C 8E470008 0480FFDA 26520008 8FA40058 001018C0 00831021
8C440004 8C470000 04810069 00001021 10000021 8E230000 8FA50060 8FA40064
02834821 00A34021 00833021 03C32821 02E32021 02C31821 8D2C0000 8D0B0000
8CCA0000 8CA90000 8C880000 8C630000 00002021 00402821 02A03021 AFA30024
AFAC0010 AFAB0014 AFAA0018 AFA9001C AFA80020 0411FE8F 00000000 8E240000
8FA50058 26730001 0264202A 1480000D 00B21821 8E230000 0203182A 10600036
8FA40058 001018C0 00832821 8CA40004 04800031 8CA70000 26120001 10000008
001290C0 8C640004 26450008 0480FFF1 8C670000 02401821 1000FFCF 00A09021
8FA50060 8FA40064 02834821 00A34021 00833021 03C32821 02E32021 02C31821
8D2C0000 8D0B0000 8CCA0000 8CA90000 8C880000 8C630000 24040002 00402821
02A03021 AFA30024 AFAC0010 AFAB0014 AFAA0018 AFA9001C AFA80020 0411FE5D
00000000 8E240000 8FA50058 26100001 0204202A 10800008 00B21821 8C640004
26450008 04800004 8C670000 02401821 1000FFDB 00A09021 8FBF004C 00021FC3
8FBE0048 000210C3 8FB70044 8FB60040 8FB5003C 8FB40038 8FB30034 8FB20030
8FB1002C 8FB00028 03E00008 27BD0050 26120001 001290C0 02009821 1000FF96
00001021
End CFunction




 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 982
Posted: 12:18am 10 Apr 2016
Copy link to clipboard 
Print this post

Peter you do some amazing stuff.....

PS on the Big Ben glass can I read cafe?

GM
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9590
Posted: 12:39am 10 Apr 2016
Copy link to clipboard 
Print this post

Nice one!

@ OA47 - Yes, you can. I can see it too, and there is another word under that, but I can't make it out.
Smoke makes things work. When the smoke gets out, it stops!
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10223
Posted: 12:44am 10 Apr 2016
Copy link to clipboard 
Print this post

  Quote  PS on the Big Ben glass can I read cafe?


Some sort of watermark on the image lew247 sent me. Seems to say "cafe press"

Update

Just realised my test main loop wasn't keeping time properly. This works as it should

do
secs=val(right$(time$,2))
mins=val(mid$(time$,4,2))
hours=val(left$(time$,2))
hands(secs,mins,hours,(MM.Vres\2-MM.Vres\12),MM.Hres\2, MM.Vres\2)
do
loop while val(right$(time$,2))=secs
loop
Edited by matherp 2016-04-11
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 01:45am 10 Apr 2016
Copy link to clipboard 
Print this post

That is totally amazing, it just astounds me how helpful this forum is.
Thank you so much

I know this is a "silly question" and is probably impossible
but is it easy or hard to scale the clock down in size?
ie so it sits on say the 1st 1/3rd of the display on the left hand side? even if there is a gap above and below it?

And yes unfortunately the example kind of image I sent matherp was from cafepress and has their logo on the picture as a watermark
I'm trying to find a similar kind of picture without a watermark, that can be used properly in a project like thisEdited by lew247 2016-04-11
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 05:58am 10 Apr 2016
Copy link to clipboard 
Print this post

Attached, Royalty Free picture (very similar to the above)
Definitely no watermarks, I bought the picture to get it royalty free - so feel free to use it.
Size 480 X 480 so it will fit in the program perfectly.


Unfortunately I cannot upload the zip file of the correct .bmp file as it's too large.
Right click on the picture and you should be able to download it.
Edit: for some reason when you download it, it's coming up as a .png file - but you can convert it to .bmp using any program or send me a message with your email address if you want me to send you the original which is a lot larger (or this size in bmp format)



Edited by lew247 2016-04-11
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 10:41am 17 Jun 2016
Copy link to clipboard 
Print this post

2016-06-17_204306_bigben.zip Matherp - or anyone else

Could somone be so kind as to tell me the mods to get the hands of the clock showing in the correct position and size please?

I have resized the clock face so it's 240X240 pixels and have it positioned on the left hand side of the screen in the centre of the display

I have it showing correctly where i want it with the following section of code

[code]load image "bigben.bmp",0,120 [/code]

However I cannot work out how to get the actual clock hands in the correct position.

[code]
Circle MM.Hres\2, MM.Vres\2, (MM.Vres\2-MM.Vres\12)\12, 0, , rgb(red), rgb(red))
Circle MM.Hres\2, MM.Vres\2, (MM.Vres\2-MM.Vres\12)\15, 0, , 0, 0
Circle MM.Hres\2, MM.Vres\2, (MM.Vres\2-MM.Vres\12)\20, 0, , RGB(gray), RGB(gray)
[/code]

I believe that is the centre circles of the clock and it gets its position by asking the display what size it is then dividing that size by 2 to get it in the centre (MM.Hres\2, MM.Vres\2)

I THINK that's how it works
[code]hands(secs,mins,hours,(MM.Vres\2-MM.Vres\12),MM.Hres\2, MM.Vres\2)[/code]

I THINK that does the same with the hands

The bit I cannot work out is how to position the hands in the centre of my clock!!!!!

It should be easy to figure out but myt brain is not letting me see the simple answer
it's probably something like

[code]Circle MM.Hres\6, MM.Vres\4, (MM.Vres\6-MM.Vres\12)\12, 0, , rgb(red), rgb(red))
Circle MM.Hres\6, MM.Vres\4, (MM.Vres\6-MM.Vres\12)\15, 0, , 0, 0
Circle MM.Hres\6, MM.Vres\4, (MM.Vres\6-MM.Vres\12)\20, 0, , RGB(gray), RGB(gray)
[/code]

BUT I cannot work it out

Anyone able to help please?

I've included the 240X240 bmp in the zip file

Edited by lew247 2016-06-18
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 10:51am 17 Jun 2016
Copy link to clipboard 
Print this post

You know the exact size of the bitmap and you know where you put it on the screen. Work with those values and not use the Hres and VRes variables.

If the bitmap is 240x240 and you placed it at 0,120
then the center will be 0+120, 120 + 120 -> x=120,y=240

Draw a small circle to make sure you are exactly in the center, then work from there.
Edited by MicroBlocks 2016-06-18
Microblocks. Build with logic.
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 11:24pm 17 Jun 2016
Copy link to clipboard 
Print this post

I would, but I'm not sure how to make these bits appear in the right place orr how the position is worked out
[code](MM.Vres\6-MM.Vres\12)\12, 0[/code]
And I'm not certain how the arm lenghts are worked out
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 08:44am 18 Jun 2016
Copy link to clipboard 
Print this post

What I need to do somehow is move the centre of the clock to 120,360
and then make the size of all the hands 1/2 the size they are now

Actually thinking about it some more, I could work round the clock being in the centre of the display

However I would still need to work out (or be told ideally) how to make the hands 1/2 the size they are now
Edited by lew247 2016-06-19
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10223
Posted: 10:03pm 18 Jun 2016
Copy link to clipboard 
Print this post

Lewis

This really isn't hard. Look at the definition of the hands subroutine:

Sub hands(seconds As integer, minutes as integer, hours as integer, size as integer, x as integer, y as integer)


x and y are the coordinates where you want the centre of the hands, i.e. in the middle of your clock face. Size is the length of the biggest hand in pixels. I found by experimentation that with the bigben image the size should be 5/6ths of half the image height in your case 5/6*120 = 100. But if this isn't quite right just try something else!

The lines

  Quote  Circle MM.Hres\2, MM.Vres\2, (MM.Vres\2-MM.Vres\12)\12, 0, , rgb(red), rgb(red))
Circle MM.Hres\2, MM.Vres\2, (MM.Vres\2-MM.Vres\12)\15, 0, , 0, 0
Circle MM.Hres\2, MM.Vres\2, (MM.Vres\2-MM.Vres\12)\20, 0, , RGB(gray), RGB(gray)


Can probably omitted completely.

In general you need to just try things and see what happens. If you don't understand what

  Quote  (MM.Vres\2-MM.Vres\12)\15


is doing put in a print statement and see what value it is generating and then think about what value you might need for your size of display.

The whole point of interpretive Basic is that you can repeatedly modify/retest code until it does what you want. If in this example the hands end up somewhere incorrect then just make a change and rerun you can't do any harm.

I have all my code on Dropbox. This has the advantage that you can always recover a previous version without having to remember to take backups - very useful.Edited by matherp 2016-06-20
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 11:36pm 18 Jun 2016
Copy link to clipboard 
Print this post

Thank you Peter

I had been "playing/experimenting" with the code and had figured out how to move the centre circles of the clock it was the size of the hands that I had the main problem with


One last question if you don't mind and I am sorry for asking so many questions

I have the clock reading the time from the RTC on power up

I want the clock to read the time from the RTC every 12 hours to make sure the time is 100% accurate
This code seems to work but I have no way of knowing if it actually is

Can you tell me if it is formatted correctly and it will actually read the time every 12 hours?
[code]do
secs=val(right$(time$,2))
mins=val(mid$(time$,4,2))
hours=val(left$(time$,2))
hands(secs,mins,hours,(MM.Vres\2-MM.Vres\12),MM.Hres\2, MM.Vres\2)
do
loop while val(right$(time$,2))=secs
If hours = 12 Then RTC GETTIME
loop
[/code]
Thanks
Edited by lew247 2016-06-20
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 12:28am 19 Jun 2016
Copy link to clipboard 
Print this post

Peter

I've got the position of the clock sorted and the hand sized

The one problem I cannot figure out is how to change the size of the second hand
I've tried changing various bits of code but none seems to change the size of the second hand

Any clues where to start looking please?

Or could you explain to me how the sizing for the second hand works please?

This is the size of the hands
[code] hands(secs,mins,hours,(MM.Vres\2-MM.Vres\4),MM.Hres\2, MM.Vres\2) [/code]

If I change MM.Vres\4 to MM.Vres\3 all the hands get smaller but too small
and MM.Vres\5 makes them too big

I'd like to keep them the size as they are just make the second hand say 20% smaller in length if possible

Apart from that the only other question is regarding the time in the previous post.

Thanks



LewisEdited by lew247 2016-06-20
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 12:55am 19 Jun 2016
Copy link to clipboard 
Print this post

  lew247 said  
I want the clock to read the time from the RTC every 12 hours to make sure the time is 100% accurate
This code seems to work but I have no way of knowing if it actually is

Can you tell me if it is formatted correctly and it will actually read the time every 12 hours?
[code]do
secs=val(right$(time$,2))
mins=val(mid$(time$,4,2))
hours=val(left$(time$,2))
hands(secs,mins,hours,(MM.Vres\2-MM.Vres\12),MM.Hres\2, MM.Vres\2)
do
loop while val(right$(time$,2))=secs
If hours = 12 Then RTC GETTIME
loop
[/code]
Thanks


You could just do this:-

[Code]
'Re-Sync with RTC 24 hours. Will repeat for a 10 second period.
if left$(time$,7)="00:00:0" then
rtc gettime
Print "Clock Resync'd"
Endif
[/code]

Or

[Code]
'Re-Sync with RTC every hour. Will repeat for a 10 second period.
if mid$(time$,4,4)="00:0" then
rtc gettime
Print "Clock Resync'd"
Endif
[/code]

Adding an OR to the first one would enable Sync every 12 hours.

Cheers
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10223
Posted: 08:31am 29 Jun 2016
Copy link to clipboard 
Print this post

I was converting the CFunction to work on an Explore100 board (100-pin MX470) and discovered there was an error in the way the CFunction worked in certain orientations so please find attached a revised version for the 64-pin part and a new version for the 100-pin part together with the amended C source

100-pin MX470

CFunction triangles
00000267
'defineregion
3C029D00 8C420090 24080100 3C03BF88 AC686434 80420015 2488FFFF 24A3FFFF
01064021 24060001 10460004 00671821 24060003 14460005 3C029D00 00805821
01005021 10000008 00602021 8C420094 00605821 00A05021 8C430000 2463FFFF
00682823 00642023 000B6202 000A4202 3C02BF88 24060200 24090100 00053A02
00041A02 35080300 358C0300 356B0300 240D022A AC4D6430 354A0300 AC466434
34E70300 AC466438 34A50300 AC496438 34630300 AC4C6430 34840300 AC466434
AC466438 AC4B6430 AC466434 AC466438 AC486430 2408022B AC466434 AC466438
AC4A6430 AC466434 AC466438 AC496434 AC486430 AC466434 AC466438 AC496438
AC476430 AC466434 AC466438 AC456430 AC466434 AC466438 AC436430 AC466434
AC466438 AC446430 AC466434 AC466438 03E00008 00000000
'writeRectangle
27BDFFD8 AFB40020 AFB3001C 00C0A021 00E09821 72749802 AFB00010 8FB00038
AFB20018 AFB10014 00109403 00108A03 AFBF0024 0411FFA4 00000000 3C02BF88
24030100 24040200 2405022C AC436434 36520300 AC456430 36310300 AC446434
36100300 AC446438 AC436438 1260000F 2673FFFF 24030200 2404FFFF 2673FFFF
AC526430 AC436434 AC436438 AC516430 AC436434 AC436438 AC506430 AC436434
AC436438 1664FFF6 2673FFFF 8FBF0024 8FB40020 8FB3001C 8FB20018 8FB10014
8FB00010 03E00008 27BD0028
'ReadRectangle
27BDFFC8 AFBF0034 AFBE0030 AFB7002C AFB60028 AFB50024 AFB40020 AFB3001C
AFB20018 3C139D00 AFB10014 AFB00010 8E630090 0080B021 8E620028 8064002D
00C0A821 00E0F021 00A0B821 0040F809 8FB10048 8E640090 8E630024 24050006
8084002D 24100001 0060F809 00508004 8E630090 00409021 8E620024 8064002D
24050005 0040F809 0015A040 0295A021 00409821 729E1002 02C02021 02E02821
02A03021 03C03821 0051A021 0411FF53 00000000 3C05BF88 24060100 ACA66434
8FA3004C 24070200 2402022E ACA26430 ACA76434 ACA76438 ACA66438 240600FF
00711821 3C02BF81 3C04BF88 ACA6641C AE700000 8C45F220 8C45F220 8C45F220
AE500000 8C866420 26310003 0234282B A0660000 AE700000 8C46F220 8C46F220
8C46F220 AE500000 8C866420 A0660001 AE700000 8C46F220 8C46F220 8C46F220
AE500000 8C866420 A0660002 14A0FFE8 24630003 3C02BF88 240300FF AC43641C
8FBF0034 02201021 8FBE0030 8FB7002C 8FB60028 8FB50024 8FB40020 8FB3001C
8FB20018 8FB10014 8FB00010 03E00008 27BD0038
'RestoreRectangle
27BDFFE0 AFB20018 AFB10014 00C09021 00E08821 72328802 AFB00010 AFBF001C
8FB00030 0411FF10 00000000 3C02BF88 24030100 24040200 2405022C AC436434
AC456430 AC446434 AC446438 AC436438 1220001D 2631FFFF 8FA40034 02202821
00902021 24030200 2407FFFF 80860000 24A5FFFF 34C60300 AC466430 AC436434
AC436438 80860001 34C60300 AC466430 AC436434 AC436438 80860002 24840003
34C60300 AC466430 AC436434 AC436438 54A7FFEF 80860000 00111040 26100003
00518821 02118021 8FBF001C 02001021 8FB20018 8FB10014 8FB00010 03E00008
27BD0020
'triangles
27BDFFA8 AFB20038 8FA3006C 00809021 8FA40074 AFBE0050 AFB7004C 0083102A
AFB3003C AFB10034 AFBF0054 AFB60048 AFB50044 AFB40040 AFB00030 00A09821
00C0B821 AFA70064 8FB10068 10400006 8FBE007C 02201021 AFA4006C 8FB10070
AFA30074 AFA20070 8FA30074 03C3102A 10400009 8FA6006C 8FA20070 8FA40078
AFBE0074 AFA20078 AFA40070 0060F021 8FA6006C 8FA30074 0066102A 50400008
8FA6006C 8FA40074 02201021 AFA60074 8FB10070 AFA4006C AFA20070 8FA6006C
14DE0036 8FA30074 8FA30070 0071102A 14400006 02203821 0223102A 10400005
8FA40078 10000002 8FA70070 8FB10070 8FA40078 0091102A 54400003 8FB10078
00E4102A 0082380B 1640000C 24020001 8FA5006C 24E70001 02202021 24060001
00F13823 AFB30010 AFB70014 0411FF16 00000000 100000B0 00409821 1642000C
8FA20064 8FA5006C 24E70001 02202021 24060001 00F13823 AFB30010 AFB70014
0411FF6E 00000000 100000A3 00409821 8FA5006C 24E70001 02202021 24060001
00F13823 AFA20010 AFB70014 0411FECB 00000000 10000099 8FBF0054 8FA4006C
007E1026 0002102B 00621023 AFA20020 0044102A 14400044 00808021 8FA60070
8FA20078 00641823 00D13023 00511023 03C42023 AFA60024 AFA20028 0000A021
0000A821 AFA30018 AFA4001C 24160001 8FA40018 8FA6001C 02002821 02A4001A
008001F4 02C03821 00001012 00511021 0286001A 00C001F4 00001812 00711821
0062302A 10C00003 00402021 00601021 00801821 24660001 00402021 16400009
00C23023 02002821 02C03821 AFB30010 AFB70014 0411FECC 00000000 10000012
00409821 5656000C 8FA20064 24630001 00402021 02002821 00623023 02C03821
AFB30010 AFB70014 0411FF24 00000000 10000005 00409821 AFB70014 AFA20010
0411FE86 00000000 8FA30020 8FA40024 8FA60028 26100001 0070102A 02A4A821
1040FFCB 0286A021 03D0102A 1440004A 8FA30070 8FA20078 8FA40074 8FA60078
00431023 AFA20024 8FA2006C 0204A023 00D13023 0202A823 8FA20024 70D5A802
03C41823 8FA4006C AFA60020 AFA30018 03C42023 AFA4001C 24160001 7054A002
8FA40018 8FA6001C 02002821 0284001A 008001F4 8FA40070 02C03821 00001012
00441021 02A6001A 00C001F4 00001812 00711821 0062202A 10800003 00403021
00601021 00C01821 24660001 00402021 16400009 00C23023 02002821 02C03821
AFB30010 AFB70014 0411FE7F 00000000 10000012 00409821 5656000C 8FA20064
24630001 00402021 02002821 00623023 02C03821 AFB30010 AFB70014 0411FED7
00000000 10000005 00409821 AFB70014 AFA20010 0411FE39 00000000 8FA30024
8FA40020 26100001 03D0102A 0283A021 1040FFCB 02A4A821 8FBF0054 02601021
8FBE0050 8FB7004C 8FB60048 8FB50044 8FB40040 8FB3003C 8FB20038 8FB10034
8FB00030 03E00008 27BD0058
'gettearscanline
27BDFFE0 AFBF001C AFB20018 AFB10014 AFB00010 3C109D00 8E030090 8E020028
0040F809 8064002D 8E030090 00409021 8E020024 8064002D 0040F809 24050006
8E030090 00408821 8E020024 8064002D 0040F809 24050005 24040001 3C03BF88
02449004 24060100 24070200 240500FF 24080245 AC666434 3C04BF81 AC686430
AC676434 AC676438 AC666438 AC65641C AC520000 8C86F220 8C86F220 8C86F220
8C86F220 AE320000 8C666420 AC520000 8C82F220 8C82F220 8C82F220 8C82F220
AE320000 8C626420 AC65641C 8FBF001C 30C400FF 00042200 304200FF 00821025
8FB20018 8FB10014 8FB00010 03E00008 27BD0020
'main
27BDFFB0 AFBE0048 AFB70044 AFB60040 8FBE0068 8FB7006C 8FB60070 AFB5003C
AFB40038 AFB1002C AFBF004C AFB30034 AFB20030 AFB00028 00808821 00A0A821
AFA60058 00E0A021 0411FFB0 00000000 2442FE70 2C42000A 1040FFFB 00000000
8E220000 184000A0 00008021 8FA20058 8C440004 04810025 8C470000 8FB20058
00001821 00001021 00008021 8FA40060 8FA50064 02834821 00834021 00A33021
02E32021 03C32821 02C31821 8D2C0000 8D0B0000 8CCA0000 8CA90000 8C880000
8C630000 24040001 00402821 02A03021 AFA30024 AFAC0010 AFAB0014 AFAA0018
AFA9001C AFA80020 0411FE7D 00000000 8E240000 26100001 0204202A 1480000E
001018C0 1000006A 00001021 8FA40058 001018C0 00831021 8C440004 8C470000
0480002A 00001021 26120001 001290C0 10000007 02009821 8E44000C 8E470008
0480FFD2 26520008 1000FFF1 8FA40058 8FA50060 8FA40064 02834821 00A34021
00833021 03C32821 02E32021 02C31821 8D2C0000 8D0B0000 8CCA0000 8CA90000
8C880000 8C630000 00002021 00402821 02A03021 AFA30024 AFAC0010 AFAB0014
AFAA0018 AFA9001C AFA80020 0411FE4C 00000000 8E240000 8FA50058 26730001
0264202A 1480000D 00B21821 8E230000 0203182A 10600036 8FA40058 001018C0
00832821 8CA40004 04800031 8CA70000 26120001 10000008 001290C0 8C640004
26450008 0480FFF1 8C670000 02401821 1000FFCF 00A09021 8FA50060 8FA40064
02834821 00A34021 00833021 03C32821 02E32021 02C31821 8D2C0000 8D0B0000
8CCA0000 8CA90000 8C880000 8C630000 24040002 00402821 02A03021 AFA30024
AFAC0010 AFAB0014 AFAA0018 AFA9001C AFA80020 0411FE1A 00000000 8E240000
8FA50058 26100001 0204202A 10800008 00B21821 8C640004 26450008 04800004
8C670000 02401821 1000FFDB 00A09021 8FBF004C 00021FC3 8FBE0048 000210C3
8FB70044 8FB60040 8FB5003C 8FB40038 8FB30034 8FB20030 8FB1002C 8FB00028
03E00008 27BD0050 1000FFF1 00001021
End CFunction


64-pin MX470

00000267
'defineregion
3C029D00 8C420090 24081000 3C03BF88 AC686134 80420015 2488FFFF 24A3FFFF
01064021 24060001 10460004 00671821 24060003 14460005 3C029D00 00805821
01005021 10000008 00602021 8C420094 00605821 00A05021 8C430000 2463FFFF
00682823 00642023 000B6202 000A4202 3C02BF88 24060800 24091000 00053A02
00041A02 35081800 358C1800 356B1800 240D022A AC4D6430 354A1800 AC466134
34E71800 AC466138 34A51800 AC496138 34631800 AC4C6430 34841800 AC466134
AC466138 AC4B6430 AC466134 AC466138 AC486430 2408022B AC466134 AC466138
AC4A6430 AC466134 AC466138 AC496134 AC486430 AC466134 AC466138 AC496138
AC476430 AC466134 AC466138 AC456430 AC466134 AC466138 AC436430 AC466134
AC466138 AC446430 AC466134 AC466138 03E00008 00000000
'writeRectangle
27BDFFD8 AFB40020 AFB3001C 00C0A021 00E09821 72749802 AFB00010 8FB00038
AFB20018 AFB10014 00109403 00108A03 AFBF0024 0411FFA4 00000000 3C02BF88
24031000 24040800 2405022C AC436134 36521800 AC456430 36311800 AC446134
36101800 AC446138 AC436138 1260000F 2673FFFF 24030800 2404FFFF 2673FFFF
AC526430 AC436134 AC436138 AC516430 AC436134 AC436138 AC506430 AC436134
AC436138 1664FFF6 2673FFFF 8FBF0024 8FB40020 8FB3001C 8FB20018 8FB10014
8FB00010 03E00008 27BD0028
'ReadRectangle
27BDFFC8 AFBF0034 AFBE0030 AFB7002C AFB60028 AFB50024 AFB40020 AFB3001C
AFB20018 3C139D00 AFB10014 AFB00010 8E630090 0080B021 8E620028 8064002D
00C0A821 00E0F021 00A0B821 0040F809 8FB10048 8E640090 8E630024 24050006
8084002D 24100001 0060F809 00508004 8E630090 00409021 8E620024 8064002D
24050005 0040F809 0015A040 0295A021 00409821 729E1002 02C02021 02E02821
02A03021 03C03821 0051A021 0411FF53 00000000 3C05BF88 24061000 ACA66134
8FA3004C 24070800 2402022E ACA26430 ACA76134 ACA76138 ACA66138 240600FF
00711821 3C02BF81 3C04BF88 ACA6641C AE700000 8C45F220 8C45F220 8C45F220
AE500000 8C866420 26310003 0234282B A0660000 AE700000 8C46F220 8C46F220
8C46F220 AE500000 8C866420 A0660001 AE700000 8C46F220 8C46F220 8C46F220
AE500000 8C866420 A0660002 14A0FFE8 24630003 3C02BF88 240300FF AC43641C
8FBF0034 02201021 8FBE0030 8FB7002C 8FB60028 8FB50024 8FB40020 8FB3001C
8FB20018 8FB10014 8FB00010 03E00008 27BD0038
'RestoreRectangle
27BDFFE0 AFB20018 AFB10014 00C09021 00E08821 72328802 AFB00010 AFBF001C
8FB00030 0411FF10 00000000 3C02BF88 24031000 24040800 2405022C AC436134
AC456430 AC446134 AC446138 AC436138 1220001D 2631FFFF 8FA40034 02202821
00902021 24030800 2407FFFF 80860000 24A5FFFF 34C61800 AC466430 AC436134
AC436138 80860001 34C61800 AC466430 AC436134 AC436138 80860002 24840003
34C61800 AC466430 AC436134 AC436138 54A7FFEF 80860000 00111040 26100003
00518821 02118021 8FBF001C 02001021 8FB20018 8FB10014 8FB00010 03E00008
27BD0020
'triangles
27BDFFA8 AFB20038 8FA3006C 00809021 8FA40074 AFBE0050 AFB7004C 0083102A
AFB3003C AFB10034 AFBF0054 AFB60048 AFB50044 AFB40040 AFB00030 00A09821
00C0B821 AFA70064 8FB10068 10400006 8FBE007C 02201021 AFA4006C 8FB10070
AFA30074 AFA20070 8FA30074 03C3102A 10400009 8FA6006C 8FA20070 8FA40078
AFBE0074 AFA20078 AFA40070 0060F021 8FA6006C 8FA30074 0066102A 50400008
8FA6006C 8FA40074 02201021 AFA60074 8FB10070 AFA4006C AFA20070 8FA6006C
14DE0036 8FA30074 8FA30070 0071102A 14400006 02203821 0223102A 10400005
8FA40078 10000002 8FA70070 8FB10070 8FA40078 0091102A 54400003 8FB10078
00E4102A 0082380B 1640000C 24020001 8FA5006C 24E70001 02202021 24060001
00F13823 AFB30010 AFB70014 0411FF16 00000000 100000B0 00409821 1642000C
8FA20064 8FA5006C 24E70001 02202021 24060001 00F13823 AFB30010 AFB70014
0411FF6E 00000000 100000A3 00409821 8FA5006C 24E70001 02202021 24060001
00F13823 AFA20010 AFB70014 0411FECB 00000000 10000099 8FBF0054 8FA4006C
007E1026 0002102B 00621023 AFA20020 0044102A 14400044 00808021 8FA60070
8FA20078 00641823 00D13023 00511023 03C42023 AFA60024 AFA20028 0000A021
0000A821 AFA30018 AFA4001C 24160001 8FA40018 8FA6001C 02002821 02A4001A
008001F4 02C03821 00001012 00511021 0286001A 00C001F4 00001812 00711821
0062302A 10C00003 00402021 00601021 00801821 24660001 00402021 16400009
00C23023 02002821 02C03821 AFB30010 AFB70014 0411FECC 00000000 10000012
00409821 5656000C 8FA20064 24630001 00402021 02002821 00623023 02C03821
AFB30010 AFB70014 0411FF24 00000000 10000005 00409821 AFB70014 AFA20010
0411FE86 00000000 8FA30020 8FA40024 8FA60028 26100001 0070102A 02A4A821
1040FFCB 0286A021 03D0102A 1440004A 8FA30070 8FA20078 8FA40074 8FA60078
00431023 AFA20024 8FA2006C 0204A023 00D13023 0202A823 8FA20024 70D5A802
03C41823 8FA4006C AFA60020 AFA30018 03C42023 AFA4001C 24160001 7054A002
8FA40018 8FA6001C 02002821 0284001A 008001F4 8FA40070 02C03821 00001012
00441021 02A6001A 00C001F4 00001812 00711821 0062202A 10800003 00403021
00601021 00C01821 24660001 00402021 16400009 00C23023 02002821 02C03821
AFB30010 AFB70014 0411FE7F 00000000 10000012 00409821 5656000C 8FA20064
24630001 00402021 02002821 00623023 02C03821 AFB30010 AFB70014 0411FED7
00000000 10000005 00409821 AFB70014 AFA20010 0411FE39 00000000 8FA30024
8FA40020 26100001 03D0102A 0283A021 1040FFCB 02A4A821 8FBF0054 02601021
8FBE0050 8FB7004C 8FB60048 8FB50044 8FB40040 8FB3003C 8FB20038 8FB10034
8FB00030 03E00008 27BD0058
'gettearscanline
27BDFFE0 AFBF001C AFB20018 AFB10014 AFB00010 3C109D00 8E030090 8E020028
0040F809 8064002D 8E030090 00409021 8E020024 8064002D 0040F809 24050006
8E030090 00408821 8E020024 8064002D 0040F809 24050005 24040001 3C03BF88
02449004 24061000 24070800 240500FF 24080245 AC666134 3C04BF81 AC686430
AC676134 AC676138 AC666138 AC65641C AC520000 8C86F220 8C86F220 8C86F220
8C86F220 AE320000 8C666420 AC520000 8C82F220 8C82F220 8C82F220 8C82F220
AE320000 8C626420 AC65641C 8FBF001C 30C400FF 00042200 304200FF 00821025
8FB20018 8FB10014 8FB00010 03E00008 27BD0020
'main
27BDFFB0 AFBE0048 AFB70044 AFB60040 8FBE0068 8FB7006C 8FB60070 AFB5003C
AFB40038 AFB1002C AFBF004C AFB30034 AFB20030 AFB00028 00808821 00A0A821
AFA60058 00E0A021 0411FFB0 00000000 2442FE70 2C42000A 1040FFFB 00000000
8E220000 184000A0 00008021 8FA20058 8C440004 04810025 8C470000 8FB20058
00001821 00001021 00008021 8FA40060 8FA50064 02834821 00834021 00A33021
02E32021 03C32821 02C31821 8D2C0000 8D0B0000 8CCA0000 8CA90000 8C880000
8C630000 24040001 00402821 02A03021 AFA30024 AFAC0010 AFAB0014 AFAA0018
AFA9001C AFA80020 0411FE7D 00000000 8E240000 26100001 0204202A 1480000E
001018C0 1000006A 00001021 8FA40058 001018C0 00831021 8C440004 8C470000
0480002A 00001021 26120001 001290C0 10000007 02009821 8E44000C 8E470008
0480FFD2 26520008 1000FFF1 8FA40058 8FA50060 8FA40064 02834821 00A34021
00833021 03C32821 02E32021 02C31821 8D2C0000 8D0B0000 8CCA0000 8CA90000
8C880000 8C630000 00002021 00402821 02A03021 AFA30024 AFAC0010 AFAB0014
AFAA0018 AFA9001C AFA80020 0411FE4C 00000000 8E240000 8FA50058 26730001
0264202A 1480000D 00B21821 8E230000 0203182A 10600036 8FA40058 001018C0
00832821 8CA40004 04800031 8CA70000 26120001 10000008 001290C0 8C640004
26450008 0480FFF1 8C670000 02401821 1000FFCF 00A09021 8FA50060 8FA40064
02834821 00A34021 00833021 03C32821 02E32021 02C31821 8D2C0000 8D0B0000
8CCA0000 8CA90000 8C880000 8C630000 24040002 00402821 02A03021 AFA30024
AFAC0010 AFAB0014 AFAA0018 AFA9001C AFA80020 0411FE1A 00000000 8E240000
8FA50058 26100001 0204202A 10800008 00B21821 8C640004 26450008 04800004
8C670000 02401821 1000FFDB 00A09021 8FBF004C 00021FC3 8FBE0048 000210C3
8FB70044 8FB60040 8FB5003C 8FB40038 8FB30034 8FB20030 8FB1002C 8FB00028
03E00008 27BD0050 1000FFF1 00001021


C source

#define _SUPPRESS_PLIB_WARNING
#include <plib.h>
#include "../cfunctions.h"
#define MX470
//#define pin100
#define LANDSCAPE 1
#define PORTRAIT 2
#define RLANDSCAPE 3
#define RPORTRAIT 4
#define swap(a, b) {int t; t = a; a = b; b = t; }

#define bclrport *(volatile unsigned int *)(0xbf886134) //latch registers
#define bsetport *(volatile unsigned int *)(0xbf886138) //latch registers
#define cport *(volatile unsigned int *)(0xbf886230) //latch registers
#define cread *(volatile unsigned int *)(0xbf886220) //latch registers
#define ctrisinv *(volatile unsigned int *)(0xbf88621C) //latch registers
#define cclrport *(volatile unsigned int *)(0xbf886234) //latch registers
#define csetport *(volatile unsigned int *)(0xbf886238) //latch registers
#define eport *(volatile unsigned int *)(0xbf886430) //latch registers
#define eread *(volatile unsigned int *)(0xbf886420) //latch registers
#define etrisinv *(volatile unsigned int *)(0xbf88641C) //latch registers
#define eclrport *(volatile unsigned int *)(0xbf886434) //latch registers
#define esetport *(volatile unsigned int *)(0xbf886438) //latch registers
#define DEVID (*(volatile unsigned int *)0xBF80F220)

//Offsets into the persistent RAM of variables
#ifdef MX470
#ifndef pin100
#define RS_Pin_No 27
#define WR_Pin_No 24
#define RS_Pin 0x1000
#define WR_Pin 0x0800
#define clrport bclrport
#define setport bsetport
#else
#define RS_Pin_No 18
#define WR_Pin_No 19
#define RS_Pin 0x100
#define WR_Pin 0x200
#define clrport eclrport
#define setport esetport
#endif
#define port eport
#define read eread
#define trisinv etrisinv
#define RSLo {clrport=RS_Pin;}
#define RSHi {setport=RS_Pin;}
#define WRLo {clrport=WR_Pin;}
#define WRHi {setport=WR_Pin;}
#else
#define RS_Pin_No 4
#define WR_Pin_No 5
#define RS_Pin 0x100
#define WR_Pin 0x200
#define clrport cclrport
#define setport csetport
#define port cport
#define read cread
#define trisinv ctrisinv
#define RSLo clrport=RS_Pin
#define RSHi setport=RS_Pin
#define WRLo clrport=WR_Pin
#define WRHi setport=WR_Pin
#endif
#define Both WR_Pin | RS_Pin
#define RDLo (*(volatile unsigned int *)RDclrport)=RDpin
#define RDHi (*(volatile unsigned int *)RDsetport)=RDpin


void defineregion(long x, long y, long width,long height){ //SSD1963
long x1=x,x2=x+width-1,y1=y,y2=y+height-1;
unsigned long xstart,xend,ystart,yend,Vertical,Horizontal;
#ifdef MX470
RSLo;
#endif

if(Option->DISPLAY_ORIENTATION==LANDSCAPE || Option->DISPLAY_ORIENTATION==RLANDSCAPE){
xstart = x1;
xend = x2;
ystart = y1;
yend = y2;

} else {
xstart = y2;
xend = y1;
ystart = (HRes - 1) - x2;
yend = (HRes - 1) - x1;
}

port=0x22A ;WRLo; WRHi; // RS low
#ifdef MX470
RSHi;
#endif
port=(xstart>>8 ) | Both; WRLo; WRHi; // RS HIGH
port=(xstart) | Both; WRLo; WRHi; // RS HIGH
port=(xend>>8 ) | Both; WRLo; WRHi; // RS HIGH
port=(xend) | Both; WRLo; WRHi; // RS HIGH
#ifdef MX470
RSLo;
#endif
port=0x22B ; WRLo; WRHi; // RS low
#ifdef MX470
RSHi;
#endif
port=(ystart>>8 ) | Both; WRLo; WRHi; // RS HIGH
port=(ystart) | Both; WRLo; WRHi; // RS HIGH
port=(yend>>8 ) | Both; WRLo; WRHi; // RS HIGH
port=(yend) | Both; WRLo; WRHi; // RS HIGH RSHi;
}
void writeRectangle(int x1, int y1, int width, int height, int fc, char p[]){
unsigned long i,fhb,fmb,flb;
// make sure the coordinates are kept within the display area
// convert the colours to 888 format
fhb = (fc >> 16) | Both;
fmb = (fc >> 8) | Both;
flb = fc | Both;

defineregion(x1,y1,width,height);
#ifdef MX470
RSLo;
#endif
port=0x22C ; WRLo; WRHi; // RS low
#ifdef MX470
RSHi;
#endif
i=width*height;
while(i--){
port=fhb; WRLo; WRHi;
port=fmb; WRLo; WRHi;
port=flb; WRLo; WRHi;
}
}
int ReadRectangle(int x1, int y1, int width, int height, int pos, char p[]){
unsigned long j,n, RDpin, RDsetport, RDclrport;
RDpin=1<<GetPinBit(Option->LCD_CS);
RDsetport=(unsigned int)GetPortAddr(Option->LCD_CS,LATSET);
RDclrport=(unsigned int)GetPortAddr(Option->LCD_CS,LATCLR);
j=width*height*3+pos;
defineregion(x1,y1,width,height);
#ifdef MX470
RSLo;
#endif
port=0x22E ; WRLo; WRHi; // RS low
#ifdef MX470
RSHi;
#endif
trisinv=0xFF; //set pins to read
do { //read in the screen area to be overlayed
RDLo;
n=DEVID;n=DEVID;;n=DEVID;
RDHi;
p[pos++]=(read & 0xFF);
RDLo;
n=DEVID;n=DEVID;;n=DEVID;
RDHi;
p[pos++]=(read & 0xFF);
RDLo;
n=DEVID;n=DEVID;;n=DEVID;
RDHi;
p[pos++]=(read & 0xFF);
} while(pos<j);
trisinv=0xFF; //set pins to write
return pos;
}
int RestoreRectangle(int x1, int y1, int width, int height, int pos, char p[]){
int i;
defineregion(x1,y1,width,height);
#ifdef MX470
RSLo;
#endif
port=0x22C ; WRLo; WRHi; // RS low
#ifdef MX470
RSHi;
#endif
i=width*height;
while(i--){
port=p[pos++] | Both; WRLo; WRHi;
port=p[pos++] | Both; WRLo; WRHi;
port=p[pos++] | Both; WRLo; WRHi;
}
return pos;
}

long triangles(int mode, int buffpos, char *buff, long col, long x0, long y0, long x1, long y1,long x2, long y2) {//Cfunction
long a, b, y, last;
long dx01, dy01, dx02, dy02, dx12, dy12, sa, sb;

if (y0>y1) {
swap(y0, y1);
swap(x0, x1);
}
if (y1>y2) {
swap(y2, y1);
swap(x2, x1);
}
if (y0>y1) {
swap(y0, y1);
swap(x0, x1);
}
if(y0==y2) { // Handle awkward all-on-same-line case as its own thing
a=x0;
b=x0;
if(x1<a) {
a=x1;
} else {
if(x1>b) b=x1;
}
if(x2<a) {
a=x2;
} else {
if(x2>b) b=x2;
}
if(mode==0){
buffpos=ReadRectangle(a,y0,1,b-a+1,buffpos,buff);
} else if(mode==1) {
buffpos=RestoreRectangle(a,y0,1,b-a+1,buffpos,buff);
} else {
writeRectangle(a,y0,1,b-a+1,col,buff);
}
} else {
dx01=x1-x0; dy01=y1-y0; dx02=x2-x0; dy02=y2-y0; dx12=x2-x1; dy12=y2-y1; sa=0; sb=0;
if(y1==y2) {
last=y1; //Include y1 scanline
} else {
last=y1-1; // Skip it
}
for (y=y0;y<=last;y++){
a=x0+sa / dy01;
b=x0+sb / dy02;
sa=sa+dx01;
sb=sb+dx02;
a=x0+(x1-x0) * (y-y0) / (y1-y0);
b=x0+(x2-x0) * (y-y0) / (y2-y0);
if(a>b)swap(a,b);
if(mode==0){
buffpos=ReadRectangle(a,y,b-a+1,1,buffpos,buff);
} else if(mode==1) {
buffpos=RestoreRectangle(a,y,b-a+1,1,buffpos,buff);
} else {
writeRectangle(a,y,b-a+1,1,col,buff);
}
}
sa=dx12 * (y-y1);
sb=dx02 * (y-y0);
while (y<=y2){
a=x1+sa / dy12;
b=x0+sb / dy02;
sa=sa+dx12;
sb=sb+dx02;
a=x1+(x2-x1) * (y-y1) / (y2-y1);
b=x0+(x2-x0) * (y-y0) / (y2-y0);
if(a>b) swap(a,b);
if(mode==0){
buffpos=ReadRectangle(a,y,b-a+1,1,buffpos,buff);
} else if(mode==1) {
buffpos=RestoreRectangle(a,y,b-a+1,1,buffpos,buff);
} else {
writeRectangle(a,y,b-a+1,1,col,buff);
}
y=y+1;
}
}

return buffpos;
}
/*void setrd(long *RD){
Option->LCD_CS=*RD;
ExtCfg(Option->LCD_CS, EXT_DIG_OUT,0);
ExtCfg(Option->LCD_CS, EXT_BOOT_RESERVED,0);
PinSetBit(Option->LCD_CS, LATSET);
}*/
int gettearscanline(void){
int n,a,b,RDpin, RDsetport, RDclrport;
char x[10];
RDpin=1<<GetPinBit(Option->LCD_CS);
RDsetport=(unsigned int)GetPortAddr(Option->LCD_CS,LATSET);
RDclrport=(unsigned int)GetPortAddr(Option->LCD_CS,LATCLR);
#ifdef MX470
RSLo;
#endif
port=0x245 ; WRLo; WRHi; // RS low
#ifdef MX470
RSHi;
#endif
trisinv=0xFF; //set pins to read
RDLo;
n=DEVID;n=DEVID;n=DEVID;n=DEVID;
RDHi;
a=(read & 0xFF);
RDLo;
n=DEVID;n=DEVID;n=DEVID;n=DEVID;
RDHi;
b=(read & 0xFF);
trisinv=0xFF; //set pins to read
return (a<<8)|b;
}
long long main(long *count, char *buff, long long col[], long long x0[], long long y0[], long long x1[], long long y1[],long long x2[], long long y2[]) {//Cfunction
int i=0,j,buffpos=0;
do {
j=gettearscanline();
} while(j>409 || j<400);
while(i<*count && col<0){ //repeat for any restores
buffpos=triangles(1,buffpos,buff,col,x0,y0,x1,y1,x2,y2);
i++;
}
buffpos=0;
j=i;
while(i<*count && col>=0){ //repeat for any store and write commands
buffpos=triangles(0,buffpos,buff,col,x0,y0,x1,y1,x2,y2);
i++;
}
i=j;
while(i<*count && col>=0){ //repeat for any store and write commands
buffpos=triangles(2,buffpos,buff,col,x0,y0,x1,y1,x2,y2);
i++;
}
return buffpos>>3;
}

 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 08:38am 29 Jun 2016
Copy link to clipboard 
Print this post

The work you do is amazing
Thanks
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2932
Posted: 08:39am 26 Jul 2016
Copy link to clipboard 
Print this post

@matherp

Please can you confirm something.

I have taken the code from your original post, and replaced the 'CFunction triangles' chunk with that from your post above (for the 100pin). I am using an Explore100 with 7" TFT and MMBasic v5.2 as available on Geoff's website.

The first time I ran the code I got a CPU exception error. I re-ran it and all was ok, but I started editing the code. My question is, should I restart the MM if I change my code so that the CFunction side of things 're-establishes itself correctly'?

I ask this because if I make a single change to the code (and then don't reset), I notice something briefly flash up on the screen (several times - but way to quick to see what it is) and then I see 'BigBen'. Best way to describe it is like a total screen flicker of about 5 times, then BigBen drawn ok. HOWEVER, the hands then are sometimes drawn correctly, but more often than not are drawn in the incorrect position.

Every time I restart the MM after editing my code, all seems to work fine.

I seem to remember a historic post from you that recommended re-starting the MM if CFunctions are used so just need your feedback if thats ok

WW
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10223
Posted: 09:06pm 26 Jul 2016
Copy link to clipboard 
Print this post

  Quote  @matherp

Please can you confirm something.


I'm away from home so unable to test. You shouldn't need to reset. A possibility is that your code is using somehow assuming memory is in a certain state (i.e. zeroed) which is only the case after a reset. Is the buffer memory big enough for the triangles you are saving?

I can look at this properly late next week if you post your full code. I personally didn't see any problems when I did the Explore-100 mods.
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2932
Posted: 10:08pm 26 Jul 2016
Copy link to clipboard 
Print this post

Thanks Peter.

The code is literally your first post, with the 'CFunction triangles' replaced with the 'new' 100pin version above.

Was also using Lewis' smaller BigBen Image.

Then in the DO...LOOP I simply added PRINTing the time to the console (PRINT TIME$)

The reason I haven't posted the code is that it has long gone - but this is what I was doing when I first observed the 'screen flickering & misplaced hands'.

By the way, because of the additional time to send the TIME$ to the console, the PAUSE 1000 caused drift between the PRINTed time, and the 'analogue time' (since you are not re-reading the TIME$).
So I then brought into the DO....LOOP the few lines of code above the DO loop that set the secs, mins, hours, from the actual TIME$; and then reduced the PAUSE 1000 to PAUSE 10.

Let me be clear that your code / program works - just any change to it causes the flicker & hand mis-location occasionally, UNLESS I reset the MM in which case it works first time (every time).

I commented out the PRINT ... buffer line but noticed it was 83% (or 88%) on the first time I ran the program. Because it was 'upsetting' my display - I commented it out as the first thing I did.

Will try all this myself again latter and let you know how it goes . . .

WW


 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10223
Posted: 10:59pm 26 Jul 2016
Copy link to clipboard 
Print this post

  Quote  By the way, because of the additional time to send the TIME$ to the console,


That was a c..p way of doing it. See my second post on the first page of the thread where I replace this with a "correct" method
 
     Page 1 of 2    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025