I previously posted a program that plotted ellipses and circles on a GLCD. I've now added Hyperbolas to this software. The entire program is below.
;ChipSettings#chip 18F452,20#config OSC=HS;Includefiles(Libraries)#include<GLCD.h>;Defines(Constants)#define GLCD_DB0 PORTB.3 'D0 to pin 4 on LCD#define GLCD_DB1 PORTB.2 'D1 to pin 5 on LCD#define GLCD_DB2 PORTB.1 'D2 to pin 6 on LCD#define GLCD_DB3 PORTB.0 'D3 to pin 7 on LCD#define GLCD_DB4 PORTD.7 'D4 to pin 8 on LCD#define GLCD_DB5 PORTD.6 'D5 to pin 9 on LCD#define GLCD_DB6 PORTD.5 'D6 to pin 10 on LCD#define GLCD_DB7 PORTD.4 'D7 to pin 11 on LCD#define GLCD_CS2 PORTC.7 'D8 to pin 12 on LCD - CS1, CS2 are backwards#define GLCD_CS1 PORTC.6 'D9 to pin 13 on LCD - CS1, CS2 are backwards#define GLCD_RESET PORTC.5 'D10 to pin 14 of LCD#define GLCD_RW PORTC.4 'D11 to pin 15 of LCD#define GLCD_RS PORTD.3 'D12 to pin 16 D/I pin on LCD#define GLCD_ENABLE PORTD.2 'D13 to Pin 17 on LCD#define LCD_IO 2#define LCD_CB PORTC.1#define LCD_DB PORTC.2;VariablesDimMajVTemp2,Maj_MinTempAslong;ellipsevariablesDimMajV,MajV3,MinV,MinV3,Xvalue,Yvalue,OffsetX,OffsetY,MajVTemp,MajVTemp3AsintegerDimMinV2,MajV2,Maj_Min,Min_Maj,Xaxis_Hor_ellipse,Xaxis_Hor_ellipse2AslongDimYaxis_Hor_ellipse,Yaxis_Hor_ellipse2,Yaxis,Xaxis,y_1AslongDimTransAxis,ConjAxis,ValueX,ValueY,Xoffset,YoffsetAsinteger;hyperbolavariablesDimAxisX,AxisY,AxisXX,AxisYY,AxisX_Hor_hyperbola,ValueX2,ValueY2AsintegerDimTransAxis2,Trans_Conj,AxisX_Hor_hyperbola2AslongDimConjAxis2,AxisY_Hor_hyperbola2,AxisY_Hor_hyperbolaAslongDimG_1Aslong;squarerootvariable'InitGLCD'GLCDCLS'SampleLeft-RightHyperbolaHyperbola15,10,63,31,3;Hyperbolaincenterofdisplaywait3sGLCDCLS'SampleTop-BottomHyperbolaHyperbola5,5,63,31,4;Hyperbolaincenterofdisplaywait3sGLCDCLS'SomesampleHORIZONTALellipses-MajV>MinVEllipse20,12,5,5,0;HorizontalEllipseontopleftofdisplayEllipse20,12,85,5,0;HorizontalEllipseontoprightofdisplayEllipse20,12,5,34,0;HorizontalEllipseonbottomleftofdisplayEllipse20,12,85,34,0;HorizontalEllipseonbottomrightofdisplayEllipse58,20,6,12,0;LargecenteredHorizontalellipsewait3sGLCDCLS'SomesampleVERTICALellipses-MajV>MinVEllipse15,10,30,0,1;SmallVerticalEllipseontopleftofdisplayEllipse15,10,80,0,1;SmallVerticalEllipseontoprightofdisplayEllipse15,10,30,32,1;SmallVerticalEllipseonbottomleftofdisplayEllipse15,10,80,32,1;SmallVerticalEllipseonbottomrightofdisplayEllipse30,10,5,0,1;LargeVerticalellipseonleftsideEllipse32,10,55,0,1;LargeVerticalellipseinmiddleEllipse32,10,105,0,1;LargeVerticalellipseonrightsidewait3sGLCDCLS'SomesampleCIRCLES-MajV=MinV,HVtype=don'tcare,CircleRadius=MajV=MinVEllipse15,15,10,0;CircleontopleftofdisplayEllipse15,15,85,0;CircleontoprightofdisplayEllipse15,15,10,32;CircleonbottomleftofdisplayEllipse15,15,85,32;CircleonbottomrightofdisplayEllipse20,20,43,10;Circleincenterofdisplay'SUBROUTINES********************************************''******************************************************SubHyperbola(InTransAxis,InConjAxis,InXoffset,InYoffset,InHypType)'ConjAxis2=ConjAxis*ConjAxis;ConjugateAxissquaredTransAxis2=TransAxis*TransAxis;TransAxissquaredTrans_Conj=(100*TransAxis2)/ConjAxis2;Scaleupby100'******************************************************IfHypType=3thenForValueY=-32to32;?????????????????????????ValueY2=ValueY*ValueYOn_Off1=1;ToturnPSETonoroffOn_Off2=1AxisX_Hor_hyperbola2=(Trans_Conj*(ConjAxis2+ValueY2))/100;Scaledownby100Sq_RootAxisX_Hor_hyperbola2,AxisX_Hor_hyperbolaAxisY=ValueY+YoffsetAxisX=Xoffset-AxisX_Hor_hyperbolaAxisX_Hor_hyperbola=AxisX_Hor_hyperbola+XoffsetAxisYY=AxisY'PreventnegativevaluesfromplottingmirrorimageondisplayIf(AxisX_Hor_hyperbola>127)OR(AxisY>63)OR(AxisX_Hor_hyperbola<0)OR(AxisY<0)thenAxisX_Hor_hyperbola=0AxisY=0On_Off2=0endif'PreventnegativevaluesfromplottingmirrorimageondisplayIf(AxisX>127)OR(AxisYY>63)OR(AxisX<0)OR(AxisYY<0)thenAxisX=0AxisYY=0On_Off1=0endif'psetAxisX,AxisYY,On_Off1;LefthalfofhyperbolapsetAxisX_Hor_hyperbola,AxisY,On_Off2;RighthalfofhyperbolaNextValueYEndIf'IfHypType=4thenForValueX=-64to64ValueX2=ValueX*ValueXOn_Off1=1On_Off2=1AxisY_Hor_hyperbola2=(Trans_Conj*(TransAxis2+ValueX2))/100;Scaledownby100Sq_RootAxisY_Hor_hyperbola2,AxisY_Hor_hyperbolaAxisX=ValueX+XoffsetAxisY=AxisY_Hor_hyperbola+Yoffset;AxisY_Hor_hyperbola=Yoffset-AxisY_Hor_hyperbola;AxisXX=AxisX'PreventnegativevaluesfromplottingmirrorimageondisplayIf(AxisY_Hor_hyperbola>63)OR(AxisY>63)OR(AxisY_Hor_hyperbola<0)OR(AxisY<0)thenAxisY_Hor_hyperbola=0AxisX=0On_Off2=0endif'PreventnegativevaluesfromplottingmirrorimageondisplayIf(AxisXX>127)OR(AxisY>63)OR(AxisXX<0)OR(AxisY<0)thenAxisY=0AxisXX=0On_Off1=0endifpsetAxisX,AxisY_Hor_hyperbola,On_Off2;TophalfofhyperbolapsetAxisXX,AxisY,On_Off1;BottomhalfofhyperbolaNextValueXEndIfEndSubSubEllipse(InMajV,InMinV,InOffsetX,InOffsetY,InHVtype)'******************************************************'MajVisdistancefromcentertoamajorvertex'MinVisdistancefromcentertoaminorvertex'OffsetXisthedistancefromthey-axistotheleftmostedgeoftheellipse'OffsetYisthedistancefromthex-axistothetopmostedgeoftheellipse'HVtypeis0forHORIZONTALor1forVERTICALEllipseandnotneededforCIRCLE'SYNTAXisEllipseMajV,MinV,OffsetX,OffsetY,HVtype'******************************************************IfHVtype=1then'SwapvaluestousesameequationsforHorizontalandVerticalellipsesMajVTemp=MajVMajV=MinVMinV=MajVTemp'EndIf'******************************************************'Fora128x64GLCD-'HORIZONTALELLIPSE'If2*(MajorAxis)plusOffsetX>127,ellipsewillmoveoffRIGHTedgeofscreen'If2*(MinorAxis)plusOffsetY>63,ellipsewillmoveoffBOTTOMedgeofscreen'VERTICALELLIPSE'If2*(MajorAxis)plusOffsetY>63,ellipsewillmoveoffBOTTOMedgeofscreen'If2*(MinorAxis)plusOffsetY>127,ellipsewillmoveoffRIGHTedgeofscreen'ThebelowfourIFstatementsaddressthissituationbyreducingEllipsesizeandOffsetXand/orOffsetY'IfMinV>31thenMinV=31;keepellipseonscreenendif'IfMajV>63thenMajV=63;keepellipseonscreenendif'If((2*MajV)+OffsetX)>127thenOffsetX=127-(2*MajV)endIf'If((2*MinV)+OffsetY)>63thenOffsetY=63-(2*MinV)endIf'******************************************************'MajV3=MajV*(-1);NegativeofMajVMinV3=MinV*(-1);NegativeofMinVMinV2=MinV*MinV;MinVsquaredMajV2=MajV*MajV;MajVsquared'Maj_Min=(100*MajV2)/MinV2;Scaleupby100'Min_Maj=(100*MinV2)/MajV2;Scaleupby100''******************************************************'SolveforHorizontalEllipseX-valueandthenYvalue'SolveforVerticalEllipseY-valueandthenXvalueForYvalue=MinV3toMinVXaxis_Hor_ellipse2=(Maj_Min*(MinV2-(Yvalue*Yvalue)))/100;Scaledownby100andSolveforXSq_RootXaxis_Hor_ellipse2,Xaxis_Hor_ellipse'Yaxis=Yvalue+MinV+OffsetYXaxis=abs(Xaxis_Hor_ellipse-MajV)+OffsetXXaxis_Hor_ellipse=Xaxis_Hor_ellipse+MajV+OffsetX'psetXaxis,Yaxis,on;LefthalfofellipsepsetXaxis_Hor_ellipse,Yaxis,on;Righthalfofellipse'NextYvalue'******************************************************'FillinopeningsForXvalue=MajV3toMajVYaxis_Hor_ellipse2=(Min_Maj*(MajV2-(Xvalue*Xvalue)))/100;Scaledownby100andSolveforYSq_RootYaxis_Hor_ellipse2,Yaxis_Hor_ellipse'Xaxis=Xvalue+MajV+OffsetXYaxis=Yaxis_Hor_ellipse+MinV+OffsetY;TophalfofellipseYaxis_Hor_ellipse=abs(Yaxis_Hor_ellipse-MinV)+OffsetY;'psetXaxis,Yaxis_Hor_ellipse,on;TophalfofellipsepsetXaxis,Yaxis,on;BottomhalfofellipseNextXvalueEndSubSubSq_Root(Iny_1,G_1)'SQUAREROOTApproximationG_1=600;FirstGuessfor6Digity_1Ify_1<100000thenG_1=200;FirstGuessfor5Digity_1EndIfIfy_1<10000thenG_1=60;FirstGuessfor4Digity_1EndIfIfy_1<1000thenG_1=20;FirstGuessfor3Digity_1EndIfIfy_1<100thenG_1=6;FirstGuessfor2Digity_1EndIfIfy_1<10thenG_1=2;FirstGuessfor1Digity_1EndIf'G_1=(G_1+(y_1/G_1))/2G_1=(G_1+(y_1/G_1))/2G_1=(G_1+(y_1/G_1))/2G_1=(G_1+(y_1/G_1))/2G_1=(G_1+(y_1/G_1))/2;SquareRootofy_1EndSub
@edited by Anobium to change formatting only.
Last edit: Anobium 2014-05-17
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I previously posted a program that plotted ellipses and circles on a GLCD. I've now added Hyperbolas to this software. The entire program is below.
@edited by Anobium to change formatting only.
Last edit: Anobium 2014-05-17
A really nice piece of work.
I just copied the code, changed the start to my ST7920 GLCD and everything works. Smooth and fast.
Nice job.