Hi everyone, im trying to make the same program from assembly to C
By the way im using the microcontroler MC68HC908QY4
My program in assembly is this.
DELAY: DS 1
MyCode: SECTION
main:
_Startup:
CONFIGURATIONS:
LDA #$19
STA CONFIG1 ;no COP; no LVI; +5V
LDA #0
STA CONFIG2 ;3,2MHZ ; no extern interruption; no RESET;
LDA #$38
STA DDRA ;PTA5 , PTA4 E PTA3 outputs
INI:
GREEN:
LDA #$20
STA PTA ;turn on
BSR D1SEC
YELLOW:
LDA #$10
STA PTA ; turn on
BSR D1SEC
RED:
LDA #$08
STA PTA ;turn on
BSR D1SEC
BRA INI
D1SEC:
LDA #100
STA DELAY
D10MILI:
LDX #100
D100MICRO:
LDA #80
LOOP:
DECA
BNE LOOP
DECX
BNE D100MICRO
DEC DELAY
BNE D10MILI
RTS
END
This program uses three LEDs when choosing each output (PTA3, PTA4, PTA5), the LED is turned on, for one second, the loop D1SEC, creates a delay of 1 second.
Here is the same program but with two loops now, each loop will make the leds be turned on with diferent times. There are some minor changes now, but the program as i said is the same. The program with assembly is working fine!
INCLUDE 'derivative.inc'
XDEF _Startup, main
MY_ZEROPAGE: SECTION SHORT
TIMESIGNAL: DS 1
DELAY: DS 2
MyCode: SECTION
main:
_Startup:
CONFIGURATIONS:
MOV #$19, CONFIG1
MOV #0, CONFIG2
MOV #$38, DDRA
MOV #$1, PTAPUE
INI:
READKEY:
LDA PTA ;A=X X GREEN YELLOW RED X X CH0
AND #1; #1=0 0 0 0 0 0 0 1
BNE TEMP1 ;A=0000000CH0
TEMP0:
GREEN:
MOV #$20, PTA
MOV #5,TIMESIGNAL ;5SEC
LGREEN:
BSR D1SEG
DEC TIMESIGNAL
BNE LGREEN
YELLOW:
MOV #$10, PTA
MOV #2, TIMESIGNAL ;2SEC
LYELLOW:
BSR D1SEC
DEC TIMESIGNAL
BNE LYELLOW
RED:
MOV #$08, PTA
MOV #4, TIMESIGNAL ;4SEC
LRED:
BSR D1SEC
DEC TIMESIGNAL
BNE LRED
BRA INI
TEMP1:
GREEN1:
MOV #$20, PTA
MOV #4,TIMESIGNAL ;4SEC
LGREEN1:
BSR D1SEC
DEC TIMESIGNAL
BNE LGREEN1
YELLOW1:
MOV #$10, PTA
MOV #1, TIMESIGNAL ;1SEC
LYELLOW1:
BSR D1SEC
DEC TIMESIGNAL
BNE LYELLOW1
RED1:
MOV #$08, PTA
MOV #2, TIMESIGNAL ;2SEC
LRED1:
BSR D1SEC
DEC TIMESIGNAL
BNE LRED1
BRA INI
D1SEC:
MOV #100, DELAY+1
D10MILI:
MOV #100, DELAY
D100MICRO:
LDA #80
LOOP:
DECA
BNE LOOP
DEC DELAY
BNE D100MICRO
DEC DELAY+1
BNE D10MILI
RTS
END
And now here is my problem, when im trying to make the same code (using the code with 2 loops), it gives me an error in line 19)
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
#define RED 0x08
#define GREEN 0x20
#define YELLOW 0x10
#define DLY5 40000
#define DLY2 16000
#define DLY4 32000
#define DLY1 8000
void temporiza( unsigned long int);
void main(void)
{
CONFIG1=0x19;
CONFIG2=0x00;
DDRA=0x38;
PTAPUE=0x01;
}
if(!PTA_ PTA0) // MY PROBLEM IS IN THIS LINE
{
for( ;; )
{
PTA=GREEN;
temporiza(DLY5);
PTA=YELLOW;
temporiza(DLY2);
PTA=RED;
temporiza(DLY4);
}
else
{
PTA=GREEN;
temporiza(DLY4);
PTA=YELLOW;
temporiza(DLY1);
PTA=RED;
temporiza(DLY2);
}
}
void temporiza( unsigned long int delay)
{
while(delay--);
}
Im trying to make my if works.
Someone can help me please?
Thanks a lot for your time.