Jump to content
ELFORUM - Forumul Electronistilor
Sign in to follow this  
sorinpetrila

Ajutor Programel BASCOM

Recommended Posts

Pentru cine stie Basic si poate arunca o privire peste program sa vada ce ar putea fi in neregula. Ideea e ca programul accepta vreo 5 comenzi prin UART dar daca trimit aceeasi comanda de 2 ori, se blocheaza :sparge: . Nu cunosc limbajul si trebuie sa-l adaptez pentru ce am nevoie. Am mai primit intrebarea de ce nu stau in banca mea sa fac doar ceea ce stiu sa fac :aut: dar nu am de ales . Repet. Pentru cine are experienta si la o simpla privire ar putea vedea o greseala majora. Problema incepe de la randul 181. Programul se compileaza fara erori.Multumesc.'*******************************************************************************'Program pentru Display ST7735R 1.8 inch 128x160'Display from adafruit.com/products/358'or HY-1.8 Spi Display'Bascom IDE 2.0.7.5''Version:13092012'By Zeppelin' © Copyright by H.Kipnik 2012'Date 13.09.2012'update 03.06.2013'*******************************************************************************' SD Card CS --> portb.0' Miso --> portb.3' Mosi --> portb.2' Clock --> portb.1'Display' CS --> portb.7' DC --> portb.5' reset --> portb.6' Mosi --> portb.2' Lite --> +5V''Display typ Red or black Tab have different RGB order'color of the display plastic wrap'*******************************************************************************$regfile = "m2560def.dat"$crystal = 16000000$hwstack = 100$swstack = 100$framesize = 100'********************UART/RS 232 setari*****************************************Config Com1 = 38400 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0Config Com2 = 38400 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0Open "com1:" For Binary As #1Open "com2:" For Binary As #2Echo OffDeclare Sub Serial0charmatch()Declare Sub Serial1charmatch()Config Serialout = Buffered , Size = 254Config Serialin = Buffered , Size = 30 , Bytematch = 13Config Serialout1 = Buffered , Size = 254Config Serialin1 = Buffered , Size = 30 , Bytematch = 13Enable Interrupts'*******************************************************************************Dim Intrare As String * 30Dim Intrare1 As String * 30Dim Comanda(2) As String * 20Dim Comanda_numar As IntegerDim Lungime As ByteDim Valoare As IntegerDim Fsiniterror As Byte ' Cod de eroare atunci când sistemul de fisiere se initializeazaDim Temp As String * 100 ' Buffer pentru siruriDim Rn As WordDim I As Integer ' Numarator de variabileDim T As IntegerDim P0 As IntegerDim P1 As IntegerDim P2 As IntegerDim P4 As IntegerDim P5 As IntegerDim P6 As IntegerDim P8 As IntegerDim P9 As IntegerDim P10 As IntegerDim P16 As IntegerDim P17 As IntegerDim P18 As IntegerDim P20 As IntegerDim P21 As IntegerDim P22 As IntegerDim P24 As IntegerDim P25 As IntegerDim P26 As IntegerDim P As SingleDim Ax As SingleDim Ay As SingleDim Az As SingleDim Bn As SingleDim C As SingleDim X As SingleDim X1 As SingleDim X2 As SingleDim X3 As SingleDim Y As SingleDim B As SingleDim A As SingleDim Z As SingleDim W As SingleA = 0 'lungime coapsaB = 0 'lungime gambaBn = 0 'lungime intre servohorn si coapsaT = 2000Const Datei1 = "lesen.txt" ' fisiere pentru citireConst Datei2 = "schreib.txt" ' fisiere pentru scriereConst Software_ver = "Phoenix V2.1"'*******************************************************************************Const Sdcard = 1 'use SD Card = 1 no SD Card = 0Const Modus = 1 '0=Portrait 1=LandscapeConst Disp_typ = 0 'RGB order 0=Black Tab 1=Red Tab'*******************************************************************************Config Portb.7 = OutputConfig Portb.5 = OutputConfig Portb.6 = OutputLcd_cs Alias Portb.7Lcd_dc Alias Portb.5Lcd_reset Alias Portb.6Portb.7 = 1Enable Interrupts'*******************************************************************************$include "ST7735_declarations.inc"#if Sdcard = 1 $include "Config_MMCSD_HC.bas" $include "Config_AVR-DOS.bas" Call Init_sd_card()#endif#if Sdcard = 0 Config Portb.0 = Output 'chiar daca nu sunt folosite Portb.0 = 1 Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = High , Phase = 1 , Clockrate = 4 , Noss = 1 Spsr = 1 Spiinit#endifWait 2'Print #2 , "VER"Call Lcd_init()'Call Lcd_clear(black)'Call Lcd_pic(0 , 0 , 160 , 128 , "sorin.ebm")'Wait 1'*******************************************************************************'Call Lcd_clear(black)'Wait 1'Call Lcd_text( "Systemstart" , 5 , 2 , 2 , Red , Black)'Wait 1'Call Lcd_text( "Sorin Petrila" , 5 , 20 , 2 , Blue , Black)'Wait 1'Call Lcd_text(software_ver , 5 , 60 , 3 , Yellow , Black)'Call Lcd_text(intrare1 , 5 , 80 , 3 , Green , Red)'Wait 1'********************************Main*******************************************Main:Print #1 , "HAI CU COMANDA AIA O DATA" Call Lcd_clear(black) Waitms 200 Call Lcd_text( "Main" , 5 , 2 , 2 , Red , Black) Wait 2 ' dim variableDo Waitms 11Loop 'for everEnd'***************************Comenzi*********************************************Meniu:Lungime = Split(intrare , Comanda(1) , "/" ) Valoare = Val(comanda(2)) ' Print Comanda(1) Print Comanda(2) Select Case Comanda(1) ' ' Restart Case "RESET" Call Lcd_clear(black) Waitms 200 Call Lcd_text( "Restart..." , 5 , 2 , 3 , Red , Black) Wait 1 Goto 0 Case "VER" Call Lcd_clear(black) Waitms 200 Call Lcd_text( "Ver:" , 5 , 2 , 3 , Blue , Black) Wait 1 Call Lcd_text(software_ver , 5 , 20 , 3 , Red , Black) Wait 1 Print "Versiune Software: " ; Software_ver Print #1 , "VERSIUNE" Print #2 , "SSC: " ; Intrare1 Case "AUS" Goto Aus Case "MIDDLE" Goto Middle Case "SER_OFF" Goto Servos_aus End SelectGoto Main'*******************************************************************************'**************************SSC32 Trimiteri**************************************Ssc: Print #1 , "#0 P" ; P0 ; " #1 P" ; P1 ; " #2 P" ; P2 ; " #4 P" ; P4 _ ; " #5 P" ; P5 ; " #6 P" ; P6 ; " #8 P" ; P8 ; " #9 P" ; P9 _ ; " #10 P" ; P10 ; " #16 P" ; P16 _ ; " #17 P" ; P17 ; " #18 P" ; P18 ; " #20 P" ; P20 ; " #21 P" ; P21 _ ; " #22 P" ; P22 ; " #24 P" ; P24 ; " #25 P" ; P25 ; _ ; " #26 P" ; P26; " T" ; T Print #2 , "#0 P" ; P0 ; "#1 P" ; P1 ; "#2 P" ; P2 ; "#4 P" ; P4 _ ; "#5 P" ; P5 ; "#6 P" ; P6 ; "#8 P" ; P8 ; "#9 P" ; P9 _ ; "#10 P" ; P10 ; "#16 P" ; P16 _ ; "#17 P" ; P17 ; "#18 P" ; P18 ; "#20 P" ; P20 ; "#21 P" ; P21 _ ; "#22 P" ; P22 ; "#24 P" ; P24 ; "#25 P" ; P25 ; _ ; "#26 P" ; P26; " T" ; T Waitms T Waitms 10 ReturnServos_aus: Print #1 , "Motoare oprite" Print #2 , "#0L #1L #2L #3L #4L #5L #6L #7L #8L #9L #10L #11L #12L #13L #14L #15L #16L #17L #18L #19L #20L #21L #22L #23L #24L #25L #26L #27L #28L #29L #30L #31L #32L"Return'*******************************************************************************'***********************************SERVO***************************************Aus: 'Call Lcd_clear(black) 'Waitms 200 Call Lcd_text( "AUS" , 5 , 20 , 2 , Blue , Black) Wait 2T = 5000P0 = 1500P1 = 2300P2 = 2150P4 = 1500P5 = 2300P6 = 2150P8 = 1500P9 = 2300P10 = 2150P16 = 1500P17 = 600P18 = 800P20 = 1500P21 = 600P22 = 800P24 = 1500P25 = 600P26 = 800Goto SscReturnMiddle: 'Call Lcd_clear(black) 'Waitms 200 Call Lcd_text( "MIDDLE" , 5 , 40 , 2 , Blue , Black) Wait 2P0 = 1500P1 = 1500P2 = 1500P4 = 1500P5 = 1500P6 = 1500P8 = 1500P9 = 1500P10 = 1500P16 = 1500P17 = 1500P18 = 1500P20 = 1500P21 = 1500P22 = 1500P24 = 1500P25 = 1500P26 = 1500T = 5000Goto SscReturn'*******************************************************************************'*********************************Cinematica inversa****************************Inverse:P = Atn2(ay , Ax) C = Az ^ 2X = Ax ^ 2C = C + XC = C ^ 0.5C = C - BnC = C ^ 2X = Ay ^ 2C = C + XC = C ^ 0.5X = A ^ 2X1 = B ^ 2X2 = C ^ 2X3 = X + X1X = X - X2X1 = 2 * AX1 = X1 * BX = X / X1Y = Acos(x) X = A ^ 2X1 = B ^ 2X2 = C ^ 2X3 = X + X1X = X - X2X1 = 2 * CX1 = X1 * AX = X / X1Z = Acos(x)X = Y / CX = Acos(x)W = X - Z EndEndEndReturn'*******************************************************************************$include "ST7735_functions.inc"#if Sdcard = 1$include "SD_card_init.inc"#endif$include "Font\Font12x16.font"$include "Font\Font8x8.font"$include "Font\font8x12.font"$include "Font\font6x10.font"$include "Font\font10x16.font"'*******************************************************************************Sub Serial0charmatch() Local Incoming_data As String * 30 'Daten vom Buffer auslesen Input Incoming_data Intrare = Incoming_data Goto MeniuEnd SubSub Serial1charmatch() Local Incoming_data1 As String * 30 'Daten vom Buffer auslesen Input #2 , Incoming_data1 Intrare1 = Incoming_data1 ReturnEnd Sub Close #1 Close #2'*****************************Cinematica**************************************** Return'*******************************************************************************

Share this post


Link to post
Share on other sites

In ce ai pus tu sunt vreo 3 programe daca nu mai multe la prima vedere.Sau ai facut copy paste gresit, sau ai facut copy paste partial.Spun asta deoarece sunt multe rutine care nu se executa vreodata in vecii vecilor , pentru ca nu sunt chemate. ( In mare se intelege ce vrei sa faci dar nu e scris bine . )Din pacate nu am timp ca ti l-as fi facut eu.

Share this post


Link to post
Share on other sites

Asta e programul complet. E vorba de doua UART-uri (PC, si alt controller), un lcd si o memorie microSD. Problema o am la interuperi si subrutine. Programul nu se mai intoarce in aceeasi stare la "Main". Sigur e ceva simplu. Am sa pun mai jos doar bucata unde imi face probleme si am sa sterg parametrii secundari. Las numai comenzile.'********************************Main*******************************************Main:Print #1 , "Comanda"Call Lcd_clear(black)Waitms 200Call Lcd_text( "Main" , 5 , 2 , 2 , Red , Black)Wait 2' dim variableDoWaitms 11Loop 'for everEnd'***************************Comenzi*********************************************Meniu:Lungime = Split(intrare , Comanda(1) , "/" )Valoare = Val(comanda(2))'Print Comanda(1)Print Comanda(2)Select Case Comanda(1)'' RestartCase "RESET"Call Lcd_clear(black)Waitms 200Call Lcd_text( "Restart..." , 5 , 2 , 3 , Red , Black)Wait 1Goto 0Case "VER"Call Lcd_clear(black)Waitms 200Call Lcd_text( "Ver:" , 5 , 2 , 3 , Blue , Black)Wait 1Call Lcd_text(software_ver , 5 , 20 , 3 , Red , Black)Wait 1Print "Versiune Software: " ; Software_verPrint #1 , "VERSIUNE"Print #2 , "SSC: " ; Intrare1Case "AUS"Goto AusCase "MIDDLE"Goto MiddleCase "SER_OFF"Goto Servos_ausEnd SelectGoto Main'*******************************************************************************'**************************SSC32 Trimiteri**************************************Ssc:Print #1 , "#0 P" ; P0 ; " #1 P" ; P1 ; " #2 P" ; P2 ; TPrint #2 , "#0 P" ; P0 ; "#1 P" ; P1 ; "#2 P" ; P2 ; TWaitms TWaitms 10ReturnServos_aus:Print #1 , "Motoare oprite"Print #2 , "#0L #1L #2L #3L #4L #5L #6L #7L #8L #9L #10L #11L #12L #13L #14L #15L #16L #17L #18L #19L #20L #21L #22L #23L #24L #25L #26L #27L #28L #29L #30L #31L #32L"Return'*******************************************************************************'***********************************SERVO***************************************Aus:'Call Lcd_clear(black)'Waitms 200Call Lcd_text( "AUS" , 5 , 20 , 2 , Blue , Black)Wait 2T = 5000P0 = 1500P1 = 2300P2 = 2150Goto SscReturnMiddle:'Call Lcd_clear(black)'Waitms 200Call Lcd_text( "MIDDLE" , 5 , 40 , 2 , Blue , Black)Wait 2P0 = 1500P1 = 1500P2 = 1500T = 5000Goto SscReturn'*******************************************************************************'*********************************Cinematica inversa****************************Inverse:P = Atn2(ay , Ax)C = Az ^ 2X = Ax ^ 2C = C + XC = C ^ 0.5C = C - BnC = C ^ 2X = Ay ^ 2C = C + XC = C ^ 0.5X = A ^ 2X1 = B ^ 2X2 = C ^ 2X3 = X + X1X = X - X2X1 = 2 * AX1 = X1 * BX = X / X1Y = Acos(x)X = A ^ 2X1 = B ^ 2X2 = C ^ 2X3 = X + X1X = X - X2X1 = 2 * CX1 = X1 * AX = X / X1Z = Acos(x)X = Y / CX = Acos(x)W = X - ZEndEndEndReturn'*******************************************************************************$include "ST7735_functions.inc"#if Sdcard = 1$include "SD_card_init.inc"#endif$include "Font\Font12x16.font"$include "Font\Font8x8.font"$include "Font\font8x12.font"$include "Font\font6x10.font"$include "Font\font10x16.font"'*******************************************************************************Sub Serial0charmatch()Local Incoming_data As String * 30'Daten vom Buffer auslesenInput Incoming_dataIntrare = Incoming_dataGoto MeniuEnd SubSub Serial1charmatch()Local Incoming_data1 As String * 30'Daten vom Buffer auslesenInput #2 , Incoming_data1Intrare1 = Incoming_data1ReturnEnd SubClose #1Close #2'*****************************Cinematica****************************************Return'*******************************************************************************

Share this post


Link to post
Share on other sites

Trecand peste faptul ca programul supus atentiei(cel mai probabil copiat) este o varza, sunt doua subrutine (Sub Serial0charmatch() si Sub Serial1charmatch()) care nu sunt chemate/apelate in veci.

Ca urmare, ori nu e asta programul pe care l-ai testat (afirmi ca functioneaza partial) ori l-ai copiat partial.

Share this post


Link to post
Share on other sites

Programul complet e mai sus dar fuctioneaza partial. Totusi am sa ma opresc aici inainte sa devin penibil. Sincer apreciez timpul acordat. Am sa revin cand o sa fiu si eu mai in cunostinta de cauza si o sa stiu sa pun o intrebare coerenta :multumesc

Share this post


Link to post
Share on other sites

Uite cum se folosesc porturile software de UART in cazul Bascom :'-----------------------------------------------------------------------------------------'name : open.bas'copyright : © 1995-2005, MCS Electronics'purpose : demonstrates software UART'micro : Mega48'suited for demo : yes'commercial addon needed : no'-----------------------------------------------------------------------------------------$regfile = "m48def.dat" ' specify the used micro$crystal = 10000000 ' used crystal frequency$baud = 19200 ' use baud rate$hwstack = 32 ' default use 32 for the hardware stack$swstack = 10 ' default use 10 for the SW stack$framesize = 40 ' default use 40 for the frame spaceDim B As ByteOpen "comd.1:19200,8,n,1" For Output As #1Print #1 , "serial output"Open "comd.0:19200,8,n,1" For Input As #2Print #1 , "Number"Input #2 , BPrint #1 , BDo B = Inkey(#2)If B > 0 Then Print #1 , Chr(b) 'print the characterEnd IfLoop Until B = 27Close #2Close #1End----------------------------------------------------------------------------------Observi cum e structurat programul ?Care e logica lui ?Oricum in Atmega 2560 ai o gramada de hardware UART de ce sa folosesti software UART ?Probabil pentru ca pinii sunt ocupati cu altceva .

Share this post


Link to post
Share on other sites

Programul mai pe scurt unde am problema e mai jos. Trimit una din comenzi "aus" "middle" "reset" "ser_off". Cand trimit "ser_off" totul e ok. Cand trimit "aus" "middle", prima data functioneaza apoi daca repet una din comenzile astea, se blocheaza controllerul.Main:Print #1 , "Comanda"Call Lcd_clear(black)Waitms 200Call Lcd_text( "Main" , 5 , 2 , 2 , Red , Black)Wait 2DoWaitms 11Loop 'for everEnd'***************************Comenzi*********************************************Meniu:Lungime = Split(intrare , Comanda(1) , "/" ) Valoare = Val(comanda(2))' Print Comanda(1) Print Comanda(2) Select Case Comanda(1)'' RestartCase "RESET"Call Lcd_clear(black)Waitms 200Call Lcd_text( "Restart..." , 5 , 2 , 3 , Red , Black)Wait 1Goto 0Case "VER"Call Lcd_clear(black)Waitms 200Case "AUS"Goto AusCase "MIDDLE"Goto MiddleCase "SER_OFF"Goto Servos_ausEnd SelectGoto Main'*******************************************************************************'**************************SSC32 Trimiteri**************************************Ssc:Print #1 , "#0 P" ; P0 ; " #1 P" ; P1 ; " #2 P" ; P2 ; TPrint #2 , "#0 P" ; P0 ; "#1 P" ; P1 ; "#2 P" ; P2 ; TWaitms TWaitms 10ReturnServos_aus:Print #1 , "Motoare oprite"Print #2 , "#0L #1L #2L #3L #4L #5L #6L #7L #8L #9L #10L #11L #12L #13L #14L #15L #16L #17L #18L #19L #20L #21L #22L #23L #24L #25L #26L #27L #28L #29L #30L #31L #32L"Return'*******************************************************************************'***********************************SERVO***************************************Aus:'Call Lcd_clear(black)'Waitms 200Call Lcd_text( "AUS" , 5 , 20 , 2 , Blue , Black)Wait 2T = 5000P0 = 1500P1 = 2300P2 = 2150Goto SscReturnMiddle:'Call Lcd_clear(black)'Waitms 200Call Lcd_text( "MIDDLE" , 5 , 40 , 2 , Blue , Black)Wait 2P0 = 1500P1 = 1500P2 = 1500T = 5000Goto SscReturn'*******************************************************************************

Share this post


Link to post
Share on other sites

Si este normal sa patesti asta, deoarece in continutul subrutinei AUS (sau MIDDLE) ai comanda "GOTO SSC", iar dupa executarea subrutinei SSC (care se termina cu comanda RETURN), te va trimite inapoi la subrutina AUS (sau MIDDLE) ... si uite asa ai reusit sa pui bietul uC intr-o stare de confuzie totala.Ar trebui sa restructurezi programul intreg identificand (si eliminand) eventualele bucle infinite ssi asta se face pas cu pas.

Share this post


Link to post
Share on other sites

Totul e aiurea dar iti sugerez sa faci asa ca sa poti face debug :Select Case Comanda(1)Case "RESET"Call Lcd_clear(black)Waitms 200Call Lcd_text( "Restart..." , 5 , 2 , 3 , Red , Black)Case "VER"Call Lcd_clear(black)Waitms 200Case "AUS"Goto AusCase "MIDDLE"Goto MiddleCase "SER_OFF"Goto Servos_ausEnd SelectGoto MainSsc:Print #1 , "#0 P" ; P0 ; "#1 P" ; P1 ; "#2 P" ; P2 ; TPrint #2 , "#0 P" ; P0 ; "#1 P" ; P1 ; "#2 P" ; P2 ; TReturnServos_aus:Print #1 , "Motoare oprite"Print #2 , "#0L #1L #2L #3L #4L #5L #6L #7L #8L #9L #10L #11L #12L #13L #14L #15L #16L #17L #18L #19L #20L #21L #22L #23L #24L #25L #26L #27L #28L #29L #30L #31L #32L"ReturnAus:Print #1 , "Am trimis AUS !"Wait 2T = 5000P0 = 1500P1 = 2300P2 = 2150Goto SscReturnMiddle:'Print #1 , "Am trimis MIDDLE !"Wait 2P0 = 1500P1 = 1500P2 = 1500T = 5000Goto SscReturn---------------------------------------------------------------------------------si ar trebui sa vezi pe serial ca iti raspunde .

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.