Sari la conținut
ELFORUM - Forumul electronistilor

BASCOM


yo9hnf

Postări Recomandate

pune te rog tot codul! ca poate reusesc sa te ajut eu!EDIT: intre timp am incercat eu ceva!Incearca asa: Config Pind.0 = InputSet Portd.0Text Alias Pind.0 If Text = 0 ThenClsLocate 1 , 5Lcd "Text1"Wait 5clsEnd IfIf Text = 1 ThenClsLocate 1 , 5Lcd "Text2"Wait 5clsEnd Ifsi spune-mi daca e ok!Nu am circuitul dar daca zici ca-l ai tu programeaza si vezi daca e ok! logic ar trebui sa fie!Tu ai bagat functia dar doar pentru "text 1" cand pind.0 este 0 (in scurt cu masa) dar nu iai spus ce sa faca cand pind.0 este 1 (cand ramane in " aer" legat la intrerupator)

Link spre comentariu

Imi pare rau dupa cum am spus nu pot pune codul..este personal...daca nu reusesc sa il fac din soft merge hardware...Nu este bun cum ai spus....text-2 este pe lcd tot timpul nu are treaba cu pind.0, Pe mine ma intereseaza cand pind.0 este o (in scurt la masa) sa afiseze text-1 DOAR pentru 5-10 secunde, dupa care text-1 sa dispara si sa apara inapoi text-2, DAR pind.0 sa ramana tot 0 (in scurt la masa)...

Link spre comentariu

nu stiu ce sa zic atunci! eu cu o astfel de situatie nu m-am confruntat pana acum! Totusi vezi ca se poate cred ca, cu activarea si folosirea unui timer care sa-ti sesizeze ca acel port este in valoarea 0 pentru mai mult timp si nu doar pentru un impuls :da iar atunci sa treaca la "text2" sau configurezi inca o data "text2" care de fafapt va fi text3 dar va fi la fel cu text2

Link spre comentariu

Tie de fapt iti trebuie un detector de front cazator pe o anumita intrare, sa fie luat in calcul doar frontul cazator indiferent daca intrarea ramane in 0 sau 1, urmata de afisarea temporizata a unui mesaj.Asta se poate face folosint intreruperile externe INT0 sau INT1 (PD2,PD3 la atmega8).In registrul MCUCR care se ocupa de setariile acestor intreruperi ai optiunea "The falling edge of INTx generates an interrupt request". Asa ca studiaza datasheet la capitolu intreruperi externe, apoi exemplele din bascom, intr-un final vei putea scrie si codul care iti trebuie.Solutia nr.2:Setezi un flag, sa-l numim flag_monitorizare_intrare.doIf intrare = 1 then flag_monitorizare_intrare = 1If flag_monitorizare_intrare = 1 thenif intrare = 0 thenLcd "text1"aici un delay sau pornesti un timer configurat in prealabil ca sa cronometrezi x secundeCls : Lcd"text2"flag_monitorizare_intrare = 0endifendifloopAstfel va fi luat in calcul doar acel 0 la intrare care urmeaza dupa un 1 (pentru ca doar la un 1 este setat flagul care este testat in bucla if si sters la fiecare realizare a conditiei, adica la fiecare 0 detectat). Continuarea starii de 0 a intrarii nu va mai genera validari ale buclei iff pentru ca flagul va ramane pe 0 pana la urmatoarea trecere pe 1 a intrarii.

Link spre comentariu

Multumesc, am rezolvat...isa acum am alta problema am spus si o pagina in urma, vreau sa fac cu atmega8 un fel de autoscalare, de exemplu la 5v sa imi inchida un releu la 10v al dolea si tot asa mai departe, am scris un program, dar sunt mai mult ca sigur ca nu am scris ceva bine deoarece imi da eroare la "case" '$sim$regfile = "m8def.dat"$crystal = 8000000Config Pinc.0 = OutputConfig Pinc.1 = Output Set Portc.0 Set Portd.1 Case > 321 Alias Pinc.0 Case > 521 Alias Pinc.1Dim Adcv As Word , Volt As SingleConst Dif = 5 / 1024Const Volt_div = 0.02083Config Adc = Single , Prescaler = Auto , Reference = AvccStart AdcDo Adcv = Getadc(0) ' 0 = ADC0 Waitms 50 'Calcul Volt = Adcv * Dif Volt = Volt / Volt_div Select Case Case > 321 Set Portc.0 Case > 521 Set Portc.1 Reset Portc.0 EndL.E. Nu vazusem ca am configurat acelasi pin si pentru ADC si pentru releu, dar am modificat si tot aceleasi erori imi da..

Link spre comentariu

Incearca de test codul de mai jos. L-am scris in graba si nu este testat hardware.

 

$sim$regfile = "m8def.dat"$crystal = 8000000$hwstack = 32$swstack = 10$framesize = 40Config Portc.0 = OutputConfig Portc.1 = OutputDim Adcv As Word , Volt As SingleConst Dif = 5 / 1024Const Volt_div = 0.02083Config Adc = Single , Prescaler = Auto , Reference = AvccStart AdcDoAdcv = Getadc(2)         'ADC2  Waitms 50'Calcul'Volt = Adcv * Dif'Volt = Volt / Volt_div'Print AdcvSelect Case AdcvCase 0 To 321: Portc.0 = 0 Print "Releu1 inactiv" Portc.1 = 0 Print "Releu2 inactiv"Case 322 To 521: Portc.0 = 1 Print "Releu1 activ" Portc.1 = 0 Print "Releu2 inactiv"Case 522 To 1023: Portc.0 = 1 Print "Releu1 activ" Portc.1 = 1 Print "Releu2 activ"End SelectLoop
Link spre comentariu

Multumkesc Iulian, chiar functioneaza, insa a trebuit sa schimb porturile din nu stiu ce cauza releul 2 oscila continuu la orice tensiune...dar functioneaza foarte bine.Multumesc...

Link spre comentariu

deoarece imi da eroare la "case"

Si ca sa si intelegi de ce nu ti-a mers (ca poate o sa mai ai nevoie si altadata), putem vedea in help sintaxa instructiunii case

SyntaxSELECT CASE var CASE test1 : statements[CASE test2 : statements ]CASE ELSE : statementsEND SELECTRemarksVar Variable to test the value ofTest1 Value to test for.Test2 Value to test for.You can test for conditions to like: CASE IS > 2 :Another option is to test for a range : CASE 2 TO 5 :

Cu alte cuvinte structura CASE e continuta intre SELECT CASE..END SELECT si are nevoie de o variabila (var) pe care sa o testeze fata de "punctele de test" test1, test2...In cazul tau, la case-urile de la configurare iti lipseste totul (si SELECT CASE, si END SELECT, si variabila), iar la cele de la ADC e ceva mai bine, ai SELECT CASE, da' n-ai variabila, iar END SELECT e doar END.PS Helpul de la Bascom mi s-a parut chiar interesant.
Link spre comentariu
  • 3 săptămâni mai târziu...

Vezi mai jos un exemplu de la o placa de evaluare:

 

'--------------------------------------------------------------------------''                        Testtool.bas                                      ''                   2006 ,Pollin Electronic                                ''                          Freeware                                        ''--------------------------------------------------------------------------''                                                                          ''Pollin Electronic Atmel-Evaluation-Board                                  ''Bestellnummer: 810022                                                     ''Testprogramm für ATmega16                                                 ''Der gesendete Text kann mit dem Hyperterminal von Windows angezeigt werden'                                                               ''Einstellungen am Hyperterminal:                                           ''              Bits pro sekunde:   9600                                    ''              Datenbits       :      8                                    ''              Parität         :  keine                                    ''              Stoppbits       :      1                                    ''              Flusssteuerung  :  keine                                    ''                                                                          ''--------------------------------------------------------------------------'$regfile = "m16def.dat"                                     'definieren des verwendeten Chips$crystal = 8000000                                          'definieren des verwendeten externen Quarz (8MHz)Dim A As Byte                                               'dimensionieren der verwendeten VariablenDim B As ByteDdrd = &B11100000                                           'definieren der verwendeten Ports ( 1 = ausgang; 0= eingang)Portd = &B00000000                                          'definieren der einzelnen Pins an einem Port ( 0= low level; 1= high level)Main:                                                       'HauptprogrammDo                                                          'Anfang der Schleife  If Pind.2 = 1 Then                                        'Wenn an Pin 2 von Port D ein high level anliegt, dann...  Toggle Portd.5                                            '...setze Pin 5 von Port D von high auf low oder umgekehrt  Bitwait Pind.2 , Reset                                    'warte bis an Pin 2 von Port D wieder ein low level anliegt  End If                                                    'Ende der Bedingung  If Pind.3 = 1 Then                                        'Wenn an Pin 3 von Port D ein high level anliegt, dann...  Toggle Portd.6                                            '...setze Pin 6 von Port D von high auf low oder umgekehrt  Bitwait Pind.3 , Reset                                    'warte bis an Pin 3 von Port D wieder ein low level anliegt  End If                                                    'Ende der Bedingung  If Pind.4 = 1 Then                                        'Wenn an Pin 2 von Port D ein high level anliegt, dann...  Gosub Beep                                                '...gehe zum Untermenü "Beep"  Gosub Textausgabe                                         '...gehe zum Untermenü "Textausgabe"  Bitwait Pind.4 , Reset                                    'warte bis an Pin 4 von Port D wieder ein low level anliegt  End If                                                    'Ende der BendingungLoop                                                        'zum Anfang der SchleifeBeep:                                                       'Untermenü "Beep"  Portd.7 = 1                                               'setzte den Pin 7 von Port D auf high  Waitms 500                                                'Warte 500 ms  Portd.7 = 0                                               'setzt den Pin 7 von Port D auf lowReturn                                                      'zurück zum HauptmenüTextausgabe:                                                'Untermenü "Textausgabe"  Print "Atmel-Evaluation-Board"                            'Sende den Text in den Anführungszeichen über RS232 zum PCReturn                                                      'zurück zum Hauptmenü
Link spre comentariu

Si aici un alt exemplu pe care l-am si testat hardware si functioneaza:

 

'--------------------------------------------------------------------------''                        Testtool.bas                                      ''                   2006 ,Pollin Electronic                                ''                          Freeware                                        ''--------------------------------------------------------------------------''                                                                          ''Pollin Electronic Atmel-Evaluation-Board                                  ''Bestellnummer: 810022                                                     ''Testprogramm für ATmega16                                                 ''Der gesendete Text kann mit dem Hyperterminal von Windows angezeigt werden'                                                               ''Einstellungen am Hyperterminal:                                           ''              Bits pro sekunde:   9600                                    ''              Datenbits       :      8                                    ''              Parität         :  keine                                    ''              Stoppbits       :      1                                    ''              Flusssteuerung  :  keine                                    ''                                                                          ''--------------------------------------------------------------------------'$regfile = "m1284pdef.dat"                                  'definieren des verwendeten Chips$crystal = 16000000                                         'definieren des verwendeten externen Quarz (8MHz)Baud = 9600Config Portd.7 = OutputSpeaker Alias Portd.7Dim A As Byte                                               'dimensionieren der verwendeten VariablenDim B As ByteDdrd = &B11100000                                           'definieren der verwendeten Ports ( 1 = ausgang; 0= eingang)Portd = &B00000000                                          'definieren der einzelnen Pins an einem Port ( 0= low level; 1= high level)Main:                                                       'HauptprogrammDo                                                          'Anfang der Schleife  If Pind.2 = 1 Then                                        'Wenn an Pin 2 von Port D ein high level anliegt, dann...  Toggle Portd.5                                            '...setze Pin 5 von Port D von high auf low oder umgekehrt  Bitwait Pind.2 , Reset                                    'warte bis an Pin 2 von Port D wieder ein low level anliegt  End If                                                    'Ende der Bedingung  If Pind.3 = 1 Then                                        'Wenn an Pin 3 von Port D ein high level anliegt, dann...  Toggle Portd.6                                            '...setze Pin 6 von Port D von high auf low oder umgekehrt  Bitwait Pind.3 , Reset                                    'warte bis an Pin 3 von Port D wieder ein low level anliegt  End If                                                    'Ende der Bedingung  If Pind.4 = 1 Then                                        'Wenn an Pin 2 von Port D ein high level anliegt, dann...  Gosub Textausgabe                                         '...gehe zum Untermenü "Textausgabe"  Gosub Audio                                               '...gehe zum Untermenü "Beep"  Bitwait Pind.4 , Reset                                    'warte bis an Pin 4 von Port D wieder ein low level anliegt  End If                                                    'Ende der BendingungLoop                                                        'zum Anfang der SchleifeTextausgabe:                                                'Untermenü "Textausgabe"  'Print "Atmel-Evaluation-Board"                            'Sende den Text in den Anführungszeichen über RS232 zum PC  Print "Ai apasat butonul 3"  Print "Canta muzica"ReturnAudio:                                                      'Untermenü "Beep"Sound Speaker , 124 , 675                                   'H2(1/16)Sound Speaker , 110 , 758                                   'A2(1/16)Sound Speaker , 248 , 675                                   'H2(1/8)Waitms 125                                                  'P(1/16)Sound Speaker , 165 , 1011                                  'E2(1/8)Waitms 250                                                  'P(1/8)Waitms 125                                                  'P(1/16)Sound Speaker , 131 , 637                                   'C3(1/16)Sound Speaker , 124 , 675                                   'H2(1/16)Sound Speaker , 131 , 637                                   'C3(1/16)Waitms 125                                                  'P(1/16)Sound Speaker , 124 , 675                                   'H2(1/16)Waitms 125                                                  'P(1/16)Sound Speaker , 220 , 758                                   'A2(1/8)Waitms 125                                                  'P(1/16)Waitms 250                                                  'P(1/8)Sound Speaker , 131 , 637                                   'C3(1/16)Sound Speaker , 124 , 675                                   'H2(1/16)Sound Speaker , 262 , 637                                   'C3(1/8)Waitms 125                                                  'P(1/16)Sound Speaker , 165 , 1011                                  'E2(1/8)Waitms 250                                                  'P(1/8)Waitms 125                                                  'P(1/16)Sound Speaker , 110 , 758                                   'A2(1/16)Sound Speaker , 98 , 850                                    'G2(1/16)Sound Speaker , 110 , 758                                   'A2(1/16)Waitms 125                                                  'P(1/16)Sound Speaker , 98 , 850                                    'G2(1/16)Waitms 125                                                  'P(1/16)Sound Speaker , 92 , 901                                    'Fis2(1/16)Waitms 125                                                  'P(1/16)Sound Speaker , 110 , 758                                   'A2(1/16)Waitms 125                                                  'P(1/16)Sound Speaker , 196 , 850                                   'G2(1/8)Waitms 500Sound Speaker , 124 , 675                                   'H2(1/16)Sound Speaker , 110 , 758                                   'A2(1/16)Sound Speaker , 248 , 675                                   'H2(1/8)Waitms 125                                                  'P(1/16)Sound Speaker , 165 , 1011                                  'E2(1/8)Waitms 250                                                  'P(1/8)Waitms 125                                                  'P(1/16)Sound Speaker , 131 , 637                                   'C3(1/16)Sound Speaker , 124 , 675                                   'H2(1/16)Sound Speaker , 131 , 637                                   'C3(1/16)Waitms 125                                                  'P(1/16)Sound Speaker , 124 , 675                                   'H2(1/16)Waitms 125                                                  'P(1/16)Sound Speaker , 220 , 758                                   'A2(1/8)Waitms 125                                                  'P(1/16)Waitms 250                                                  'P(1/8)Sound Speaker , 131 , 637                                   'C3(1/16)Sound Speaker , 124 , 675                                   'H2(1/16)Sound Speaker , 262 , 637                                   'C3(1/8)Waitms 125                                                  'P(1/16)Sound Speaker , 165 , 1011                                  'E2(1/8)Waitms 250                                                  'P(1/8)Waitms 125                                                  'P(1/16)Sound Speaker , 110 , 758                                   'A2(1/16)Sound Speaker , 98 , 850                                    'G2(1/16)Sound Speaker , 110 , 758                                   'A2(1/16)Waitms 125                                                  'P(1/16)Sound Speaker , 98 , 850                                    'G2(1/16)Waitms 125                                                  'P(1/16)Sound Speaker , 92 , 901                                    'Fis2(1/16)Waitms 125                                                  'P(1/16)Sound Speaker , 110 , 758                                   'A2(1/16)Waitms 125                                                  'P(1/16)Sound Speaker , 196 , 850                                   'G2(1/8)Waitms 500Sound Speaker , 124 , 675                                   'H2(1/16)Sound Speaker , 110 , 758                                   'A2(1/16)Sound Speaker , 248 , 675                                   'H2(1/8)Waitms 125                                                  'P(1/16)Sound Speaker , 165 , 1011                                  'E2(1/8)Waitms 250                                                  'P(1/8)Waitms 125                                                  'P(1/16)Sound Speaker , 131 , 637                                   'C3(1/16)Sound Speaker , 124 , 675                                   'H2(1/16)Sound Speaker , 131 , 637                                   'C3(1/16)Waitms 125                                                  'P(1/16)Sound Speaker , 124 , 675                                   'H2(1/16)Waitms 125                                                  'P(1/16)Sound Speaker , 220 , 758                                   'A2(1/8)Waitms 125                                                  'P(1/16)Waitms 250                                                  'P(1/8)Sound Speaker , 131 , 637                                   'C3(1/16)Sound Speaker , 124 , 675                                   'H2(1/16)Sound Speaker , 262 , 637                                   'C3(1/8)Waitms 125                                                  'P(1/16)Sound Speaker , 165 , 1011                                  'E2(1/8)Waitms 250                                                  'P(1/8)Waitms 125                                                  'P(1/16)Sound Speaker , 110 , 758                                   'A2(1/16)Sound Speaker , 98 , 850                                    'G2(1/16)Sound Speaker , 110 , 758                                   'A2(1/16)Waitms 125                                                  'P(1/16)Sound Speaker , 98 , 850                                    'G2(1/16)Waitms 125                                                  'P(1/16)Sound Speaker , 92 , 901                                    'Fis2(1/16)Waitms 125                                                  'P(1/16)Sound Speaker , 110 , 758                                   'A2(1/16)Waitms 125                                                  'P(1/16)Sound Speaker , 196 , 850                                   'G2(1/8)Waitms 500Sound Speaker , 124 , 675                                   'H2(1/16)Sound Speaker , 110 , 758                                   'A2(1/16)Sound Speaker , 248 , 675                                   'H2(1/8)Waitms 125                                                  'P(1/16)Sound Speaker , 165 , 1011                                  'E2(1/8)Waitms 250                                                  'P(1/8)Waitms 125                                                  'P(1/16)Sound Speaker , 131 , 637                                   'C3(1/16)Sound Speaker , 124 , 675                                   'H2(1/16)Sound Speaker , 131 , 637                                   'C3(1/16)Waitms 125                                                  'P(1/16)Sound Speaker , 124 , 675                                   'H2(1/16)Waitms 125                                                  'P(1/16)Sound Speaker , 220 , 758                                   'A2(1/8)Waitms 125                                                  'P(1/16)Waitms 250                                                  'P(1/8)Sound Speaker , 131 , 637                                   'C3(1/16)Sound Speaker , 124 , 675                                   'H2(1/16)Sound Speaker , 262 , 637                                   'C3(1/8)Waitms 125                                                  'P(1/16)Sound Speaker , 165 , 1011                                  'E2(1/8)Waitms 250                                                  'P(1/8)Waitms 125                                                  'P(1/16)Sound Speaker , 110 , 758                                   'A2(1/16)Sound Speaker , 98 , 850                                    'G2(1/16)Sound Speaker , 110 , 758                                   'A2(1/16)Waitms 125                                                  'P(1/16)Sound Speaker , 98 , 850                                    'G2(1/16)Waitms 125                                                  'P(1/16)Sound Speaker , 92 , 901                                    'Fis2(1/16)Waitms 125                                                  'P(1/16)Sound Speaker , 110 , 758                                   'A2(1/16)Waitms 125                                                  'P(1/16)Sound Speaker , 196 , 850                                   'G2(1/8)Waitms 500Return                                                      'zurück zum Hauptmenü
Link spre comentariu

Multumesc pentru ajutor, dar se pare ca este mult mai complicat decat ma asteptam, cred ca cel mai usor imi este sa fac separat un buzzer cu un NE555 si sa il activez printr-un port pentru 2-3 secunde, montajul cu 555 va fi alimentat printr-un tranzistor...Multumesc.

Link spre comentariu

Am reusit cu problema de mai sus multumesc tuturor, insa mai am o problema, am reusit sa scriu un cod de volt-ampermetru, insa vreau sa imi afiseze si Wati, cum calculez? am cautat dar nu am gasit si nici nu imi dau seama, atasez mai jos codul care la-m scris...Multumesc.Adcv = Getadc(0) ' 0 = ADC0 Waitms 10 'Calcul Volt = Adcv * Dif Volt = Volt / Volt_div Locate 1 , 1 Lcd "V-" Locate 1 , 3 Lcd Fusing(volt , "##.##") Adcv = Getadc(3) ' 3 = ADC3 Waitms 10 'Calcul. Volt = Adcv * Dif Volt = Volt / 0.1 Locate 1 , 10 Lcd "A-" Locate 1 , 12 Lcd Fusing(volt , "##.##") LoopEnd

Link spre comentariu

Creează un cont sau autentifică-te pentru a adăuga comentariu

Trebuie să fi un membru pentru a putea lăsa un comentariu.

Creează un cont

Înregistrează-te pentru un nou cont în comunitatea nostră. Este simplu!

Înregistrează un nou cont

Autentificare

Ai deja un cont? Autentifică-te aici.

Autentifică-te acum
×
×
  • Creează nouă...

Informații Importante

Am plasat cookie-uri pe dispozitivul tău pentru a îmbunătății navigarea pe acest site. Poți modifica setările cookie, altfel considerăm că ești de acord să continui.Termeni de Utilizare si Ghidări