OpenCores
URL https://opencores.org/ocsvn/signed_unsigned_multiplier_and_divider/signed_unsigned_multiplier_and_divider/trunk

Subversion Repositories signed_unsigned_multiplier_and_divider

[/] [signed_unsigned_multiplier_and_divider/] [trunk/] [findprimes.bs2] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 zpekic
' ============================================================================
2
'
3
' {$STAMP BS2}
4
' {$PBASIC 2.5}
5
' ============================================================================
6
 
7
' -----[ Pins/Constants/Variables ]-------------------------------------------
8
SDA            PIN      14  'P0 transceives to/from SDA
9
SCL            PIN      15  'P1 sends clock pulses
10
START          PIN      13  'Button to select true/magnetic north mode
11
DRDY           PIN      12  'Indicates data is ready
12
 
13
 
14
' ---------- DL1414 constants and variables ---------------------
15
D0  PIN 0
16
D1  PIN 1
17
D2  PIN 2
18
D3  PIN 3
19
D4  PIN 4
20
D5  PIN 5
21
D6  PIN 6
22
nWE74 PIN 9
23
nWE30 PIN 8
24
A0    PIN 10
25
A1    PIN 11
26
 
27
char VAR Byte
28
led VAR Byte
29
i VAR Byte
30
 
31
Arg0 VAR Word
32
Arg1 VAR Word
33
N     VAR Word
34
M     VAR Word
35
 
36
Digits DATA "0123456789ABCDEF"
37
 
38
'LedBufferLen CON 8
39
'LedBuffer VAR Byte(LedBufferLen)
40
 
41
 
42
' -----[ Main Routine ]-------------------------------------------------------
43
 
44
  DIRS = %0000111101111111
45
  GOSUB ClearDisplay
46
  GOSUB TestAll
47
 
48
WaitForStart:
49
  'DEBUG CLS
50
  DEBUG CR, "From:" : DEBUGIN DEC5 Arg0
51
  DEBUG CR, "  To:" : DEBUGIN DEC5 Arg1
52
  'IF (START = 1) THEN GOTO WaitForStart
53
  i = 0
54
  n = Arg0
55
LoopN:
56
  IF (n > Arg1) THEN GOTO WaitForStart
57
  IF (n < 2) THEN GOTO NextN
58
  IF (n < 4) THEN GOTO FoundPrime '2, 3
59
  m = 1
60
NextM:
61
  m = m + 1
62
  'DEBUG CR, "Trying n = ", DEC n, " m = ", DEC m
63
  IF (n // m = 0) THEN GOTO NextN
64
  IF (m * m >= n) THEN GOTO FoundPrime
65
  GOTO NextM
66
FoundPrime:
67
  GOSUB PrintN
68
NextN:
69
  n = n + 1
70
  GOTO LoopN
71
 
72
PrintN:
73
  i = i + 1
74
  DEBUG CR, "(", DEC i, ") PRIME = ", DEC N
75
  RETURN
76
 
77
' ----- Display on 2 DL1414 LEDs ------------------------------------------
78
DisplayCharOnLed:
79
    char = char & %01111111 ' only 7 pins for character data
80
    IF (char >= "a") AND (char <="z") THEN   ' convert lowercase to uppercase
81
      char = char - 32
82
    ENDIF
83
    OUTL = char ' put code to data lines
84
    LOOKUP (led & %00000011), [%11110011, %11110111, %11111011, %11111111], OUTH ' put out address for digits
85
    IF ((led & 7) > 3) THEN
86
      'DEBUG "displayed '", STR char,"' on lower DL1414 position ",DEC pos,CR
87
      LOW nWE74
88
      HIGH nWE74
89
    ELSE
90
      'DEBUG "displayed '", STR char,"' on upper DL1414 position ",DEC pos,CR
91
      LOW nWE30
92
      HIGH nWE30
93
    ENDIF
94
    'led = led - 1
95
RETURN
96
 
97
TestAll:
98
  FOR char = %00100000 TO %01011111
99
    FOR led = 0 TO 7
100
      GOSUB DisplayCharOnLed
101
    NEXT
102
    'PAUSE 100
103
  NEXT
104
  GOSUB ClearDisplay
105
RETURN
106
 
107
ClearDisplay:
108
  char = " "
109
  led = 7
110
  FOR i = 0 TO 7
111
    'LedBuffer(led) = char
112
    GOSUB DisplayCharOnLed
113
  NEXT
114
RETURN
115
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.