This is an update to my previous post. I have added parabolas and filled ellipses/circles to my previous program. This version can plot all four conic sections on a GLCD.
;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;VariablesDimMajVTemp2,Maj_MinTempAslong;ellipsevariablesDimMajV,MajV3,MinV,MinV3,Xvalue,Yvalue,OffsetX,OffsetY,MajVTemp,MajVTemp3Asinteger;ellipsevariablesDimMinV2,MajV2,Maj_Min,Min_Maj,Xaxis_Hor_ellipse,Xaxis_Hor_ellipse2Aslong;ellipsevariablesDimYaxis_Hor_ellipse,Yaxis_Hor_ellipse2,Yaxis,Xaxis,y_1Aslong;ellipsevariablesDimTransAxis,ConjAxis,ValueX,ValueY,Xoffset,YoffsetAsinteger;hyperbolavariablesDimAxisX,AxisY,AxisXX,AxisYY,AxisX_Hor_hyperbola,ValueX2,ValueY2Asinteger;hyperbolavariablesDimTransAxis2,Trans_Conj,AxisX_Hor_hyperbola2Aslong;hyperbolavariablesDimConjAxis2,AxisY_Hor_hyperbola2,AxisY_Hor_hyperbolaAslongDimAterm,Bterm,Cterm,Xterm2,OffX,OffY,Xt,YtAsinteger;parabolavariablesDimXterm,Yterm,Yterm2,XtermNew,YtermNewAsinteger;parabolavariablesDimG_1Aslong;squarerootvariable'June3,2014'ThisprogramisusedtoplotParabolas,Hyperbolas,EllipsesandCirclesonan'128x64GLCD.ItcandobothOPENandFILLEDellipses/circles.Duetothewholenumbers'usedbyGCB,theperimetersoftheshapesarenotcompletelysmooth.Thisisparticualary'noticeablewiththeparabolawherethecalculatedvalueisderivedfromthesquareof'theinputnumber,i.e.asmallchangeontheinputproducesalargechangeontheoutput.'Whenplottingthis,asmalldeltax(psetX)givesalargedeltay(psetY).Forthis'reason,intheparabolaSubtheLINEsubwasusedinlieuofthePSETsub.'InitGLCDGLCDCLS''SampleVerticalParabolas-HVorientation=0forVerticalParabolaParabola1,12,5,20,30,0;VERTICALParabolaonleftsideofdisplayParabola1,12,5,50,30,0;VERTICALParabolaincenterofdisplayParabola-1,12,5,100,5,0;ReversedVERTICALParabolaonrightsideofdisplaywait3sGLCDCLS'SampleHorizontalParabolas-HVorientation=1forHorizontalParabolaParabola1,12,5,40,35,1;HORIZONTALParabolaatcenterofdisplayParabola9,20,20,60,7,1;VERTICALParabolaattopofdisplayParabola-5,15,10,45,50,1;ReversedVERTICALParabolaatbottomofdisplaywait3sGLCDCLS'SampleLeft-RightHyperbolaHyperbola15,10,63,31,3;Hyperbolaincenterofdisplaywait3sGLCDCLS'SampleTop-BottomHyperbolaHyperbola5,5,63,31,4;Hyperbolaincenterofdisplaywait3sGLCDCLS'SomesampleOPENHORIZONTALellipses-MajV>MinV,HVtype=0,Open_Fill=0Ellipse20,12,5,5,0,0;HorizontalEllipseontopleftofdisplayEllipse20,12,85,5,0,0;HorizontalEllipseontoprightofdisplayEllipse20,12,5,34,0,0;HorizontalEllipseonbottomleftofdisplayEllipse20,12,85,34,0,0;HorizontalEllipseonbottomrightofdisplayEllipse58,20,6,12,0,0;LargecenteredHorizontalellipsewait3sGLCDCLS'SomesampleFILLEDHORIZONTALellipses-MajV>MinV,HVtype=0,Open_Fill=1Ellipse20,12,5,5,0,1;HorizontalEllipseontopleftofdisplayEllipse20,12,85,5,0,1;HorizontalEllipseontoprightofdisplayEllipse20,12,5,34,0,1;HorizontalEllipseonbottomleftofdisplayEllipse20,12,85,34,0,1;HorizontalEllipseonbottomrightofdisplaywait3sGLCDCLS'SomesampleOPENVERTICALellipses-MajV>MinV,HVtype=1,Open_Fill=0Ellipse15,10,30,0,1,0;SmallVerticalEllipseontopleftofdisplayEllipse15,10,80,0,1,0;SmallVerticalEllipseontoprightofdisplayEllipse15,10,30,32,1,0;SmallVerticalEllipseonbottomleftofdisplayEllipse15,10,80,32,1,0;SmallVerticalEllipseonbottomrightofdisplayEllipse30,10,5,0,1,0;LargeVerticalellipseonleftsideEllipse32,10,55,0,1,0;LargeVerticalellipseinmiddleEllipse32,10,105,0,1,0;LargeVerticalellipseonrightsidewait3sGLCDCLS'SomesampleFILLEDVERTICALellipses-MajV>MinV,HVtype=1,Open_Fill=1Ellipse15,10,30,0,1,1;SmallVerticalEllipseontopleftofdisplayEllipse15,10,80,0,1,1;SmallVerticalEllipseontoprightofdisplayEllipse15,10,30,32,1,1;SmallVerticalEllipseonbottomleftofdisplayEllipse15,10,80,32,1,1;SmallVerticalEllipseonbottomrightofdisplayEllipse30,10,5,0,1,1;LargeVerticalellipseonleftsideEllipse32,10,55,0,1,1;LargeVerticalellipseinmiddleEllipse32,10,105,0,1,1;LargeVerticalellipseonrightsidewait3sGLCDCLS'SomesampleOPENCIRCLES-MajV=MinV,HVtype=don'tcare,CircleRadius=MajV=MinV,Open_Fill=0Ellipse15,15,10,0,0,0;CircleontopleftofdisplayEllipse15,15,85,0,0,0;CircleontoprightofdisplayEllipse15,15,10,32,0,0;CircleonbottomleftofdisplayEllipse15,15,85,32,0,0;CircleonbottomrightofdisplayEllipse20,20,43,10,0,0;0Circleincenterofdisplaywait3sGLCDCLS'SomesampleFILLEDCIRCLES-MajV=MinV,HVtype=don'tcare,CircleRadius=MajV=MinV,Open_Fill=1Ellipse15,15,10,0,0,1;CircleontopleftofdisplayEllipse15,15,85,0,0,1;CircleontoprightofdisplayEllipse15,15,10,32,0,1;CircleonbottomleftofdisplayEllipse15,15,85,32,0,1;CircleonbottomrightofdisplayEllipse20,20,43,10,0,1;0Circleincenterofdisplaywait3sGLCDCLS'SUBROUTINES*****************************************'SubParabola(InAterm,InBterm,InCterm,InOffX,InOffY,InHVorientation)'Usestheequationforaparabola-'y=Ax^2+Bx+Cforverticalparabolaor'x=Ay^2+By+Cforhorizontalparabola,where'AisAterm,BisBterm,andCisCterm'AnegativeAtermreversesdirectionofParabola'Cnt1=0ForXt=-63to63On_Off=1'Xterm2=Xt*XtYterm=(Aterm*Xterm2)+(Bterm*Xt)+Cterm;VERTICALParabolaEquation'IfHVorientation=1thenXterm=Yterm+OffX;ReverseparametersforHORIZONTALPARABOLAYterm=Xt+OffYElseYterm=Yterm+OffY;VERTICALPARABOLAXterm=Xt+OffXEndIf'KeepplotonGLCDscreenIfXterm>127thenXterm=127EndIf'IfXterm<0thenXterm=0EndIf'IfYTerm>63thenYterm=63EndIf'IfYterm<0thenYterm=0EndIf'TurnLINEoffwhenparabolaisoffGLCDscreenIf(Xterm=0)AND(XtermNew=0)thenOn_Off=0endif'If(Xterm=127)AND(XtermNew=127)thenOn_Off=0endif'If(Yterm=0)AND(YtermNew=0)thenOn_Off=0endif'If(Yterm=63)AND(YtermNew=63)thenOn_Off=0endif'AllowloopthroughtoestablishXtermNewandYtermNewvaluesthatareonGLCDIfCnt1=1thenLineXtermNew,YtermNew,Xterm,Yterm,On_OffendifXtermNew=Xterm;BecomespreviousXtermvalueYtermNew=Yterm;BecomespreviousYtermvalueCnt1=1NextXtEndSubSubHyperbola(InTransAxis,InConjAxis,InXoffset,InYoffset,InHypType)'Usetheequationforanhyperbola-'x^2/a^2-y^2/b^2=1whichisrearrangedto-'x^2=a^2/b^2*(b^2+y^2)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,InOpen_Fill)'Usetheequationforanellipse-'x^2/a^2+y^2/b^2=1forHorizontalellipse.Thisisrearrangedto-'x^2=a^2/b^2*(b^2-y^2)ORy^2=b^2/a^2*(a^2-x^2)'******************************************************'MajVisdistancefromcentertoamajorvertex'MinVisdistancefromcentertoaminorvertex'OffsetXisthedistancefromthey-axistotheleftmostedgeoftheellipse'OffsetYisthedistancefromthex-axistothetopmostedgeoftheellipse'HVtypeis0forHORIZONTALor1forVERTICALEllipseand0or1forCIRCLE'CIRCLEisformedbysettingMajV=Minv'Open_Fillis0forOPENor1forFILLEDEllipse'SYNTAXisEllipseMajV,MinV,OffsetX,OffsetY,HVtype,Open_Fill'******************************************************IfHVtype=1then'SwapvaluestousesameequationsforHorizontalandVerticalellipsesMajVTemp=MajVMajV=MinVMinV=MajVTempEndIf'******************************************************'Fora128x64GLCD-'HORIZONTALELLIPSE'If2*(MajorAxis)plusOffsetX>127,ellipsewillmoveoffRIGHTedgeofscreen'If2*(MinorAxis)plusOffsetY>63,ellipsewillmoveoffBOTTOMedgeofscreen'VERTICALELLIPSE'If2*(MajorAxis)plusOffsetY>63,ellipsewillmoveoffBOTTOMedgeofscreen'If2*(MinorAxis)plusOffsetY>127,ellipsewillmoveoffRIGHTedgeofscreen''******************************************************IfMinV>31thenMinV=31;keepellipseonscreenendif'IfMajV>63thenMajV=63;keepellipseonscreenendif'******************************************************'MajVtemp=MajVMinVtemp=MinVOffsetXtemp=OffsetXOffsetYtemp=OffsetY'IfOpen_Fill=0thenGotoSkipFill1endifIf(HVtype=1)AND(Open_Fill=1)thenDoWhileMinV>-1elseDoWhileMajV>-1endifSkipFill1:'If((2*MajV)+OffsetX)>127thenOffsetX=127-(2*MajV)endIf'If((2*MinV)+OffsetY)>63thenOffsetY=63-(2*MinV)endIf'IfMajV<0thenMajV=0;PreventoverflowendifMinV3=MinV*(-1);NegativeofMinVMinV2=MinV*MinV;MinVsquaredMajV2=MajV*MajV;MajVsquared'IfMinV=0thenMinV2=1;PreventDividebyzeroEndIfMaj_Min=(100*MajV2)/MinV2;Scaleupby100'******************************************************ForYvalue=MinV3toMinV'Xaxis_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'IfOpen_Fill=0thenpsetXaxis,Yaxis,on;LefthalfofellipsepsetXaxis_Hor_ellipse,Yaxis,on;RighthalfofellipseEndIfIfOpen_fill=1thenLineXaxis,Yaxis,Xaxis_Hor_ellipse,YaxisEndIf'NextYvalueMinV=MinV-1MajV=MajV-1OffsetX=OffsetX+1OffsetY=OffsetY+1If(OffsetX>OffsetXtemp+2*MajV)AND(HVtype=1)thenOffsetX=OffsetX-1;preventVerticalEllipsefromExtendinginX-axisdirectionEndIfIfOpen_Fill=1thenLoopendif'******************************************************'FillinopeningsFillOpenings:IfOpen_Fill=1thenGotoSkipFOendifMajV=MajVtempMinV=MinVtempOffsetX=OffsetXtempOffsetY=OffsetYtemp'IfOpen_Fill=0thenGotoSkipFill2endifIfHVtype=1AND(Open_Fill=1)thenDoWhileMinV>-1elseDoWhileMajV>-1endifSkipFill2:'If((2*MajV)+OffsetX)>127thenOffsetX=127-(2*MajV)endIf'If((2*MinV)+OffsetY)>63thenOffsetY=63-(2*MinV)endIf'IfMinV<0thenMinV=0;PreventoverflowendifMajV3=MajV*(-1);NegativeofMajVMinV2=MinV*MinV;MinVsquaredMajV2=MajV*MajV;MajVsquared'IfMajV=0thenMajV2=1;PreventDividebyzeroendifMin_Maj=(100*MinV2)/MajV2;Scaleupby100'ForXvalue=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;'IfOpen_Fill=0thenpsetXaxis,Yaxis_Hor_ellipse,on;TophalfofellipsepsetXaxis,Yaxis,on;BottomhalfofellipseEndIfIfOpen_Fill=1thenlineXaxis,Yaxis_Hor_ellipse,Xaxis,YaxisEndIf'NextXvalue'MinV=MinV-1MajV=MajV-1OffsetX=OffsetX+1OffsetY=OffsetY+1If(OffsetY>OffsetYtemp+2*MinV)AND(HVtype=0)thenOffsetY=OffsetY-1;preventHorizontalEllipsefromExtendinginY-axisdirectionEndIfIfOpen_Fill=1thenLoopendifSkipFO:EndSubSubSq_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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2014-06-03
MBB, that's fantastic work! Thanks for sharing it.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This is an update to my previous post. I have added parabolas and filled ellipses/circles to my previous program. This version can plot all four conic sections on a GLCD.
MBB, that's fantastic work! Thanks for sharing it.