Why does a simple delay routine produces error 116 - embedded

I have a very simple delay routine to produce delay bigger that 0.5 sec; the idea is to use TMR2, PR2 and PIC12F683; but it produces an error 116
DELAY MACRO
BANKSEL T2CON
MOVLW 0x76 ; put register w=118
MOVWF T2CON ; T2CON=W=1110111 Start TMR2 and set Postsacaler to 1110
BANKSEL PR2
MOVLW 0xC8
MOVWF PR2 ; Put PR2 to 200
**Lazo
BANKSEL T2CON
BTFSS T2CON,TOUTPS0 ;when TMR2= PR2 bit 3 (post scaler) is incremented from 1110 to 1111 then jump next instruction and end macro
GOTO Lazo****
endm
Error[116] C:\USERS\MUTANTE\MPLABXPROJECTS\CLAXON.X\MACROSDEF.INC 12 : Address label duplicated or different in second pass (Lazo)
Any idea why i got this error in the Lazo loop

When a macro is instantiated, its content is inserted verbatim, and that is what the assembler sees. If you define a label inside of a macro and then call the macro more than once, the label is defined more than once, and you will get this error.
Labels in macros must use the LOCAL directive inside of the macro definition, thus:
DELAY MACRO
LOCAL Lazo
BANKSEL T2CON
MOVLW 0x76 ; put register w=118
MOVWF T2CON ; T2CON=W=1110111 Start TMR2 and set Postsacaler to 1110
BANKSEL PR2
MOVLW 0xC8
MOVWF PR2 ; Put PR2 to 200
Lazo
BANKSEL T2CON
BTFSS T2CON,TOUTPS0 ; when TMR2= PR2 bit 3 (post scaler) is
; incremented from 1110 to 1111 then jump
; next instruction and end macro
GOTO Lazo
ENDM

Related

in z/OS Assembler, can I read a JCL input stream twice?

Is there a way to read a z/OS JCL input stream more than once? (one that comes from a //SYSIN DD *). I know I could cache the stream the first time I read it, and then read from the cached data, but I'm not interested in that solution.
Note: the language is Assembler
Depends on the language. This answer provides an example in HLASM and a reference to the 'C' Language reference at the end.
For Assembler you'll need to REWIND when you CLOSE the DCB. See the label at FINISH to see how this is done.
There may be other ways but this worked for me on z/OS 2.4
PRINT NOGEN
* ------------------------------------------------------------------- *
* *
* SYSIN2 *
* *
* #author Hogstrom *
* *
* Test to see if one can re-read SYSIN more than one time. *
* *
* ------------------------------------------------------------------- *
R0 EQU 0
R1 EQU 1
R2 EQU 2
R3 EQU 3 * Number of times to loop
R4 EQU 4
R5 EQU 5
R6 EQU 6
R7 EQU 7
R8 EQU 8
R9 EQU 9
R10 EQU 10
R11 EQU 11
R12 EQU 12 * Base Register
R13 EQU 13
R14 EQU 14
R15 EQU 15
*
SYSIN2 CSECT
STM R14,R12,12(R13)
LR R12,R15
USING SYSIN2,12
*
ST R13,SaveArea+4
LA R0,SaveArea
ST R0,8(R13)
LA R13,SaveArea
*
OPEN (SYSIN,(INPUT))
OPEN (SYSOUT,(OUTPUT))
LA R3,3 Number of times to read SYSIN
*
GETAGAIN DS 0H
GET SYSIN,INREC Read the next rec
PUT SYSOUT,INREC Write that bad boy out
B GETAGAIN
FINISH DS 0H Invoked at End of Data of SYSIN
CLOSE (SYSIN,REWIND) Close SYSIN and rewind
OPEN (SYSIN,(INPUT)) Open it up again
BCT R3,GETAGAIN Repeat the madness
*
CLOSE SYSIN
CLOSE SYSOUT
*
L R13,SaveArea+4
LM R14,R12,12(R13)
XR R15,R15
BR R14
*
SYSIN DCB DSORG=PS,MACRF=(GM),DDNAME=SYSIN,EODAD=FINISH, *
RECFM=FB,LRECL=80,BLKSIZE=0
SYSOUT DCB DSORG=PS,MACRF=(PM),DDNAME=SYSOUT, *
RECFM=FBA,LRECL=133,BLKSIZE=0
*
INREC DC CL132' '
SaveArea DS 18F
LTORG
END
Assemble the above and execute this JCL
//SYSIN2 JOB (CCCCCCCC),'HOGSTROM',
// MSGLEVEL=(1,1),
// MSGCLASS=O,
// CLASS=A,
// NOTIFY=&SYSUID
//*
//STEP1 EXEC PGM=SYSIN2
//STEPLIB DD DSN=USER1.TEST.LOADLIB,DISP=SHR
//*
//SYSIN DD *
REC 1 OF 3
REC 2 OF 3
REC 3 OF 3
/*
//SYSOUT DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
And you'll get this output
You'll see the same SYSIN data repeated three times.
For a 'C' program this reference in the IBM documentation for the C Compiler provides some hints about rewinding.
To open an in-stream data set, call the fopen() or freopen() library
function and specify the ddname of the data set. You can open an
in-stream data set only for reading. Specifying any of the update,
write, or append modes fails. Once you have opened an in-stream data
set, you cannot acquire or change the file position except by
rewinding. This means that calls to the fseek(), ftell(), fgetpos(),
and fsetpos() for in-stream data sets fail. Calling rewind() causes
z/OS XL C/C++ to reopen the file, leaving the file position at the
beginning.
What you're looking for is possible but the implementation is language dependent.

why the number of vector of INT0 is 1 not 2 as datasheet?

I am using an ATmega32 to do interrupt
when i trying to do driver of external interrupt 0 , faced me a problem
Interrupt Vectors Table in ATmega32
Interrupt Vectors code in ISR(vector)
In iom32.h code , we see that ((INT0_vect " _VECTOR(1) ")) it's number 1 but in data sheet we see that the number is 2 , why ?
The datasheet starts numbering with the reset vector. But there is no need for an explicit define (like RESET_vect) for the reset vector, since it will not be used in conjunction with ISR(). So in the header/AVRGCC implementation it is omitted.
If you compile this
ISR(INT0_vect) { }
and look at the interrupt vector table
00000000 <__vectors>:
0: 0c 94 46 00 jmp 0x8c ; 0x8c <__ctors_end>
4: 0c 94 5f 00 jmp 0xbe ; 0xbe <__vector_1>
you can see that __vector_1 is placed at byte address 4, which corresponds to the word address 2 from the data sheet.

Code Warrior Assembly code

I need some advice with a small program for school. If you could just point me in the right direction I would really appreciate it. I am using CodeWarrior coding in assembly language for the TWR-S12G128 Processor Module. My goal is to get the LEDs turn on and off with a delay of 1 second. Here is what my code looks like:
LDS #$4000 ; Initializing SP
LDAA #$FF
STAA DDRA ; Defines Port A as output
Back LDAA #$FF
STAA PORTA ; Turning all LEDs ON
JSR Delay
LDAA #$00
STAA PORTA ; Turning all LEDs OFF
JSR Delay
BSR Back
Delay PSHX ; 2-clock cycle
PSHY ; 2
LDY #20 ; 2-clock cycle
LOOP1 LDX #$FFFF ; 2
LOOP2 DEX ; 1-clock cycle
NOP ; 1-clock cycle
BNE LOOP2 ; 3-clock cycles/last cycle is 1
DEY ; 1
BNE $FF ; 3-clock cycles/last cycle is 1
PULY LOOP1 ; 3-clock cycle
PULX ; 3-clock cycle
RTS ; 5-clock cycle
There error that I am getting is :
Error : A2400: End of Line expected
main.asm line 58
Project: Project_4.mcp, Target: Standard, Source File: main.asm
Error : Compile failed
Project: Project_4.mcp, Target: Standard, Source File: main.asm
I don't know a great deal about the Freescale architecture but it's very unusual for any architecture to combine a pull instruction with a label.
The bne $ff is also unusual since that does normally specify a label.
I would be thinking that those two instructions should be more along the lines of:
bne loop1
puly
That makes more sense in that the pull instruction loses the label and the nested loops are properly constructed.
The $FF on the BNE line is not proper. I think it's a typo. I just worked this out with my professor a few hours ago. Here is the code that will give you the 1 second delay and continuously cycle the 4 LEDs on and off:
ABSENTRY Entry ; Application entry point
RAMStart EQU $2000
ROMStart EQU $C000
ORG RAMStart
; Insert here your data definition.
PTT EQU $240
DDRT EQU $242
; code section
ORG ROMStart
Entry:
_Startup:
LDS #$4000
Back LDAA #$FF
STAA DDRT
LDAA #$FF
STAA PTT
JSR Delay
LDAA #$00
STAA PTT
JSR Delay
BSR Back
Delay PSHX ; 2-clock cycle
PSHY ; 2
LDY #20 ; 2-clock cycle
LOOP1 LDX #$FFFF ; 2
LOOP2 DEX ; 1-clock cycle
NOP ; 1-clock cycle
BNE LOOP2 ; 3-clock cycles/last cycle is 1
DEY ; 1
BNE LOOP1 ; 3-clock cycles/last cycle is 1
PULY ; 3-clock cycle
PULX ; 3-clock cycle
RTS ; 5-clock cycle
ORG $FFFE
DC.W Entry ; Reset Vector
If someone would be so kind as to help me with the math. I get the 65,535 * 20 for the loops, but with the 6.25MHz clock, I end up getting .209 secs as the final amount for the delay, but I know it's suppose to be 1 sec. What am I not seeing?

expect inside while loop - loops forever

I'm new to expect scripts, so please forgive my stumbling...
Below is the meat of my expect script. The intent is to scroll thru several screens of output, after each of which the user is prompted with "Continue? [y/n]".
Finally, when there are no more screens, a "% " prompt is displayed, which SHOULD cause execution to fall out of the while loop.
set more_screens 1
while {$more_screens > 0} {
sleep 10
expect {
"\[y/n]" { send "y\r"}
"% " { set more_screens 0 }
}
}
What happens instead is... it stays in the while loop forever, sending "y" over and over and over again. I have set "exp_internal 1", and from that output it "seems" like the expect keeps re-reading text that it has already matched on, and so keeps seeing "[y/n]", and keeps sending "y" when, in fact, there are only 2 screens of output, and thus only 2 "Continue? [y/n]" prompts.
(The sleep statement is probably not necessary - i just added it to maybe solve the problem - it did NOT - and to allow me to digest the debug output better.)
Bottom line... Are there any obvious blunders in my code? I'll take any suggestions at improving this and eliminating the endless looping.
EDIT BELOW added to this question, after James made a helpful suggestion.
Thanks James for your quick response, and your helpful suggestion! But...
The same problem persists with your approach (although, yours IS much more elegant, and I'll add this to my expect tool kit.)
The problem sure seems to be, as noted initially, each execution of the expect statement RE-READS TEXT THAT WAS ALREADY READ AND COMPARED. Below is output when I execute the "exp_continue" code from James, and I set "exp_internal 1" to get debug output on my screen...
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>expect: does "get dump tables\r\n\r% get dump tables\n\r\r\nIfn TableName Configured >MaxUse InUse LastDropTime\r\n3 cdm_app 100002 190 33 >\r\n3 cdm_conv 2000002 675180 4813 \r\n3 cdm_pdisc 250002 >250002 1304 01-24-2014-19:14:59\r\n3 cdm_kpi 100001 141 25 >\r\n3 cdm_qoe 500003 204918 1578 \r\n3 cdm_qoe_hd 2500003 >582993 1578 \r\n3 cdm_kpi_error_app 100001 5 2 \r\n3 >cdm_kpi_error 100001 7 2 \r\n3 asr_cache 1000000 >1000000 999995 \r\n3 asr_sess 2000000 62670 29748 \r\n3 >asr_conn 3000000 64428 31147 \r\n3 asr_sess_keys 1500000 >1015269 1009049 \r\n3 asr_conn_opts 6000000 0 0 \r\n3 >asr_events 4000000 5239 144 \r\n3 skt_table 2000000 >2000000 2000000 \r\n3 skt_trans 1000000 408020 254674 \r\n3 >ses_sip_db 5000 0 0 \r\n3 ses_gtp_mob_txn 5000 >0 0 \r\nContinue? [y/n]: " (spawn_id exp6) match glob pattern "[y/n]"? yes
>expect: set expect_out(0,string) "n"
>expect: set expect_out(spawn_id) "exp6"
>expect: set expect_out(buffer) "get dump tables\r\n\r% get dump tables\n\r\r\nIfn"
>send: sending "y\r" to { exp6 }
>expect: continuing expect
>
>
>expect: does " TableName Configured MaxUse InUse LastDropTime\r\n3 >cdm_app 100002 190 33 \r\n3 cdm_conv 2000002 >675180 4813 \r\n3 cdm_pdisc 250002 250002 1304 01-24-2014->\r\n3 cdm_kpi 100001 141 25 \r\n3 cdm_qoe 500003 >204918 1578 \r\n3 cdm_qoe_hd 2500003 582993 1578 \r\n3 >cdm_kpi_error_app 100001 5 2 \r\n3 cdm_kpi_error 100001 >7 2 \r\n3 asr_cache 1000000 1000000 999995 \r\n3 >asr_sess 2000000 62670 29748 \r\n3 asr_conn 3000000 >64428 31147 \r\n3 asr_sess_keys 1500000 1015269 1009049 \r\n3 >asr_conn_opts 6000000 0 0 \r\n3 asr_events 4000000 >5239 144 \r\n3 skt_table 2000000 2000000 2000000 \r\n3 >skt_trans 1000000 408020 254674 \r\n3 ses_sip_db 5000 >0 0 \r\n3 ses_gtp_mob_txn 5000 0 0 \r\nContinue?
>[y/n]: " (spawn_id exp6) match glob pattern "[y/n]"? yes
>expect: set expect_out(0,string) "n"
>expect: set expect_out(spawn_id) "exp6"
>expect: set expect_out(buffer) " TableName Con"
>send: sending "y\r" to { exp6 }
>^Csighandler: handling signal(2)
>async event handler: Tcl_Eval(exit 130)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
After the expect matches on "[y/n]" the first time, it then does a "expect: continuing expect" (middle of the above text output), then the block of text it reads next is, except for the first few words, THE SAME TEXT BLOCK IT ALREADY READ AND COMPARED.
Am I missing anything??? This has to be a problem if the expect statements re-reads already processed output, yeah? (I have looked at the actual output sent by the target system, and it does NOT send out the same text block a second time.)
Again, I'm new at expect scripts, but I can't see any other explanation for what the debug output above shows. (And, I apologize for having trouble formatting the output correctly - I really am trying!)
Thanxks to anyone who has the patience to read all of the above, and perhaps has an explanation or suggestion.
You need to be rescued by the exp_continue command. :-)
What that command does when encountered is stay within the expect block and try to match again, with whatever new input may come.
So you can really shorten your above code to be:
expect {
"\[y/n]" {
send "y\r"
exp_continue
}
"% " {
# Do whatever is needed here, after which program flow will continue *outside* of the expect block
}
}
Let me know if that works out for you!
EDIT - based on #feenyman99 additional info:
Ok, I see what it is. You have the wrong pattern. By using "[y/n]", a match is being produced with a single 'n' character. There's your matched string:
expect: set expect_out(0,string) "n"
expect_out(0,string) holds the matched pattern. expect_out(buffer) holds the portion of input removed from the buffer, which holds all input up to and including the matched pattern (from then on, the next expect operation will look for a match on input after the last matched pattern). As you can see, it holds the input up to and including the first literal 'n' character that is found (newlines don't count):
expect: set expect_out(buffer) "get dump tables\r\n\r% get dump tables\n\r\r\nIfn"
So what is happening is that your script is sending the "y\r" way before the yes/no prompt is presented. And, although I'm not seeing the rest of the logs, I'm guessing the next match happens shortly after, upon hitting the next 'n' character.
So you need to change your pattern matching statement to be able to match the yes/no prompt. Better make that a regexp match (-re). I tested the following, and it works (tested on Tcl 8.4.13):
expect {
-re "\\\[y/n]" { send "y\r"}
The multiple backslashes are because the backslash is also an escape character within the pattern matcher. Kind of tricky, but sometimes they are needed.
Let me know how that goes. You should be all set now.
PS: This may come in handy: http://www.tcl.tk/doc/howto/regexp81.tml

Scale Interface to VB Application

I have a few different scales that I'm building a VB app for. Is there a universal serial port language that is common among weight scales that I can use to import real-time weight into VB?
Yes, there's a standard protocol, formulated by the Scale Manufacturer Association. The spec download is here. Whether your actual scales follow that standard is an open question, check the small print in the datasheet or programming manual for them. It is rarely a real problem, these protocols are easy with simple command/response strings.
This is what i found reading the ZBI 2/ ZPL Manuals of Zebra. very usefull!!!!
1 rem ********************************************************
05 for i = 1 to 9 step 1
10 close #i
20 next i
30 open # 2 : name "SER"
40 open # 1 : name "ZPL"
1 rem ********************************************************
1 rem main program; send serial port a 'W' in order to get a weight
1 rem ********************************************************
50 do
60 do
70 sleep 1 ! sleep so scale is not bombarded with incoming
1 rem data
80 print # 2 : "W" ; ! semicolon ends sent W without a CRLF
1 rem ********************************************************
1 rem get response from scale; note that input requires a CRLF to be
1 rem entered
1 rem ********************************************************
90 input # 2 : a$
100 if a$ = "EXIT" then! back door exit - if EXIT is received, ZBI ends
110 close # 2
120 print #1: "^XZ"
130 close #1
140 end
150 end if
1 rem ********************************************************
1 rem loop until valid weight is received, then print on label
1 rem ********************************************************
160 loop while pos ( a$ , "000.00" ) = 1 or pos ( a$ , "?" ) = 1
170 print # 1 : "~SD25^XA^FS";
180 print # 1 : "^LH0,0^FS";
190 print # 1 : "^FO56,47^A0N,69,58^FDThis weighs^FS";
1 rem ********************************************************
1 rem print weight on label; & character concatenates strings
1 rem ********************************************************
200 print # 1 : "^FO56,150^A0N,69,58^FD" & A$ & " lbs^FS";
210 print # 1 : "^PQ1,0,0,N";
220 print # 1 : "^XZ"
1 rem ********************************************************
1 rem loop until weight is off scale, then repeat for next item
1 rem weighed
1 rem ********************************************************
230 do
240 print # 2 : "W" ;
250 input # 2 : A$
260 loop until pos(A$ , "000.00") = 1 or pos(A$ , "?") = 1
270 loop