Hallo,
ik probeer een stukje code op mijn chip te plaatsen (16f628). Het compileren lukt wel, maar de chip doet niet wat het hoort te doen.
ik heb 3 ingangspoorten voor signalen, dus in totaal 8 verschillende combinaties. Afhankelijk van die combinatie laat ik 1 van de 7 lampjes branden... dat is tenminste wat ik dacht dat de code zou doen, maar tot nu toe geen geluk hiermee gehad... Kan iemand me helpen?
de code staat hieronder
Alvast bedankt,
Hussam
;---start of JAL code
include 16F628_20
include jlib
pin_b0_direction = output
pin_b1_direction = output
pin_b2_direction = output
pin_b3_direction = output
pin_b4_direction = output
pin_b5_direction = output
pin_b6_direction = output
pin_b7_direction = output
forever loop
if (pin_a2 == off) & (pin_a3 == off) & (pin_a4 == on) then
pin_b1 = on
pin_b2 = off
pin_b3 = off
pin_b4 = off
pin_b5 = off
pin_b6 = off
pin_b7 = off
pin_b0 = off
end if
if (pin_a2 == off) & (pin_a3 == on) & (pin_a4 == off) then
pin_b1 = off
pin_b2 = on
pin_b3 = off
pin_b4 = off
pin_b5 = off
pin_b6 = off
pin_b7 = off
pin_b0 = off
end if
if (pin_a2 == off) & (pin_a3 == on) & (pin_a4 == on) then
pin_b1 = off
pin_b2 = off
pin_b3 = on
pin_b4 = off
pin_b5 = off
pin_b6 = off
pin_b7 = off
pin_b0 = off
end if
if (pin_a2 == on) & (pin_a3 == off) & (pin_a4 == off) then
pin_b1 = off
pin_b2 = off
pin_b3 = off
pin_b4 = on
pin_b5 = off
pin_b6 = off
pin_b7 = off
pin_b0 = off
end if
if (pin_a2 == on) & (pin_a3 == off) & (pin_a4 == on) then
pin_b1 = off
pin_b2 = off
pin_b3 = off
pin_b4 = off
pin_b5 = on
pin_b6 = off
pin_b7 = off
pin_b0 = off
end if
if (pin_a2 == on) & (pin_a3 == on) & (pin_a4 == off) then
pin_b1 = off
pin_b2 = off
pin_b3 = off
pin_b4 = off
pin_b5 = off
pin_b6 = on
pin_b7 = off
pin_b0 = off
else
pin_b1 = off
pin_b2 = off
pin_b3 = off
pin_b4 = off
pin_b5 = off
pin_b6 = off
pin_b7 = on
pin_b0 = off
end if
end loop
Misschien wat meer info over wat er precies fout gaat? Na het compileren moet je namelijk ook nog programmeren. Gaat dat wel goed? Welke progger gebruik je? Welk schema voor je schakeling? Welke foutmeldingen krijg je eventueel?
logic
Maar dat is logisch ...
Datasheet 16F62X.PDF pag. 31:
The PORTA pins are multiplexed with comparator and
voltage reference functions. The operation of these
pins are selected by control bits in the CMCON
(comparator control register) register and the VRCON
(voltage reference control register) register. When
selected as a comparator input, these pins will read
as '0's.
EXAMPLE 5-1: Initializing PORTA
CLRF PORTA ;Initialize PORTA by
;setting output data latches
MOVLW 0x07 ;Turn comparators off and
MOVWF CMCON ;enable pins for I/O functions
BCF STATUS, RP1
BSF STATUS, RP0 ;Select Bank1
MOVLW 0x1F ;Value used to initialize data direction
MOVWF TRISA ;Set RA<4:0> as inputs
;TRISA<5> always read as ‘1’.
;TRISA<7:6> depend on oscillator mode
Je moet eerst instellen dat poort A digitale IO moet zijn.
MOVLW 0x07 ;Turn comparators off and
MOVWF CMCON ;enable pins for I/O functions
Overigens heeft kofi gelijk.
Je moet de if's binnen elkaar nesten, anders zal de LED aan pin_b7 continue branden (afgewisseld met een andere LED).
Wat je ook kan doen is de "else" vervangen door:
"if ( (pin_a2 == off) & (pin_a3 == off) & (pin_a4 == off) ) OR ( (pin_a2 == on) & (pin_a3 == on) & (pin_a4 == on) )"
(ik weet niet hoe je een OR schrijft in JAL,
maar je snapt wel wat ik bedoel)
Dan vang je de twee laatste mogelijkheden af.
[Bericht gewijzigd door logic op ]