Forum: Projekte & Code "BASIC ähnlicher" Compiler für Microchip PIC


von Feadi (Gast)


Angehängte Dateien:

Lesenswert?

Hallo,

ich habe ein Compiler für PIC µC's programmiert. Als Sourcesprache 
benutze ich etwas BASIC-Ähnliches. "Ähnlich" weil es kein echtes Basic 
ist, es erinnert nur daran. Der Compiler spuckt eine .asm Datei aus, 
diese kann man mit MPASM zu einer .hex Datei Assemblieren, oder mit 
MPLAB simulieren. In MPASM muss case sensitive deaktiviert werden. 
Unterstützt werden alle PIC's die zum 16F84 codekompatibel sind (alle 
mit 14Bit Befehlssatz).

So, jetzt zu den guten Seiten:
 - if else Konstrukte möglich
 - kein Codelimit
 - der Compiler ist kostenlos

Und die Nachteile:
 - ISR muss in Assembler programmiert werden (weil der Compiler eine 
Stacknachbildung benutzt)
 - auf Assembler kann nicht 100%tig verzichtet werden
 - die for Schleife hat einen Bug: "for i = 0 to 255" funktioniert 
nicht, keine Lösung bekannt :(
 - enthält höchstwarscheinlich noch viele unbekannte Fehler :(

Ich empfehle den Compiler nicht ernsthaft zu benutzen, wegen den bisher 
unbekannten Bugs. Sehr komfortaben ist es aber auf dem PIC ein "if else" 
Konstrukt benutzen zu können, das ist der Grund warum ich den Compiler 
hier veröffentliche. Also bitte nicht zu viel davon erwarten ;)

In der .zip Datei ist eine ganz kleine Doku und ein Beispielprogramm zu 
finden.

Zum Schluss noch ein "Hello World" Beispiel (Blinker):
1
processor 16F628a
2
asm( ; )
3
4
asm( ; --- DIM )
5
dim TRISB as extern, PORTB as extern
6
dim X as byte
7
8
asm( ; --- BANKSEL )
9
banksel TRISB
10
11
asm( ; --- TRISB[0] = 0 )
12
clr TRISB(0)
13
14
asm( ; --- BANKSEL )
15
banksel PORTB
16
17
asm( ; --- Programmschleife: )
18
schleife:
19
20
  asm( ; --- IF )
21
  if X then
22
    asm( ; --- THEN )
23
    clr PORTB(0)
24
    X = 0
25
  else
26
    asm( ; --- ELSE )
27
    set PORTB(0)
28
    X = 1
29
  endif
30
  asm( ; --- ENDIF )
31
32
  gosub wait
33
34
  goto schleife
35
36
37
wait:
38
  dim waitcount2 as byte
39
  for waitcount2 = 1 to 2
40
    gosub waitbischen
41
    gosub waitbischen
42
    gosub waitbischen
43
    gosub waitbischen
44
  next waitcount2
45
 return
46
47
waitbischen:
48
  dim waitcount as byte
49
  for waitcount = 1 to 10
50
    asm( nop )
51
    asm( nop )
52
    asm( nop )
53
    asm( nop )
54
  next waitcount
55
 return


Und die Compilerausgabe:
1
  processor 16f628a
2
  include "p16f628a.inc"
3
4
  ; 
5
  ; --- dim 
6
_x EQU 0x20
7
  ; --- banksel 
8
  banksel trisb
9
  ; --- trisb[0] = 0 
10
  bcf trisb, 0
11
  ; --- banksel 
12
  banksel portb
13
  ; --- programmschleife : 
14
_schleife:
15
  ; --- if 
16
  movf _x, w
17
  addlw 0
18
  btfsc STATUS, Z
19
  goto __label0
20
  ; --- then 
21
  bcf portb, 0
22
  movlw 0x00
23
  movwf _x
24
  goto __label1
25
__label0:
26
  ; --- else 
27
  bsf portb, 0
28
  movlw 0x01
29
  movwf _x
30
__label1:
31
  ; --- endif 
32
  call _wait
33
  goto _schleife
34
_wait:
35
_waitcount2 EQU 0x21
36
  movlw 0x01
37
  movwf _waitcount2
38
__label2:
39
  movlw 0x02
40
  subwf _waitcount2, w
41
  sublw 1
42
  btfsc STATUS, Z
43
  goto __label3
44
  call _waitbischen
45
  call _waitbischen
46
  call _waitbischen
47
  call _waitbischen
48
  incf _waitcount2, f
49
  goto __label2
50
__label3:
51
  decf _waitcount2, f
52
  return
53
_waitbischen:
54
_waitcount EQU 0x22
55
  movlw 0x01
56
  movwf _waitcount
57
__label4:
58
  movlw 0x0A
59
  subwf _waitcount, w
60
  sublw 1
61
  btfsc STATUS, Z
62
  goto __label5
63
  nop 
64
  nop 
65
  nop 
66
  nop 
67
  incf _waitcount, f
68
  goto __label4
69
__label5:
70
  decf _waitcount, f
71
  return
72
73
  end

Gruß, Feadi

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.