| Details | Message |
|---|
Read-Only Author leigh griffiths Posted 18-Apr-2007 08:43 Toolset C51 |  assembler in c, UART leigh griffiths Hi i have got code for an assembler software UART in c51. normally putchar() is of type unsigned char but with the assembler code how do i do this?
void putc()
{
#pragma asm
* Transmit character in A via TXD line
*
putc CLR TXD Drop line for start bit
MOV R0,#BITTIM Wait full bit-time
DJNZ R0,* For START bit
MOV R1,#8 Send 8 bits
putc1 RRC A Move next bit into carry
MOV TXD,C Write next bit
MOV R0,#BITTIM Wait full bit-time
DJNZ R0,* For DATA bit
DJNZ R1,putc1 write 8 bits
SETB TXD Set line high
RRC A Restore ACC contents
MOV R0,#BITTIM Wait full bit-time
DJNZ R0,* For STOP bit
RET
*
#pragma endasm
}
|
|
Read-Only Author Andy Neil Posted 18-Apr-2007 09:12 Toolset C51 |  Don't do it in 'C'!! Andy Neil 1. Write a "skeleton" putchar() in 'C' 2. Use the SRC directive to have the compiler convert this into assembler source http://www.keil.com/support/man/docs/c51/c51_src.htm 3. You now have a "skeleton" C-callable assembler routine - Throw away the 'C' skeleton! 4. Fill-in the body of the assembler "skeleton". 5. Call the function from 'C' as required. You should also read: http://www.keil.com/support/man/docs/c51/c51_ap_ctoasm.htm |
|
Read-Only Author erik malund Posted 18-Apr-2007 09:21 Toolset C51 |  That, dear friend, is the road to abject failure. erik malund my UARTS have failed....granted my fault most probably but im learning. What does that mean? that when your code does not work, instead of fixing it, you try another approach? That, dear friend, is the road to abject failure. Erik |
|
Read-Only Author leigh griffiths Posted 18-Apr-2007 09:29 Toolset C51 |  RE: Don't do it in 'C'!! leigh griffiths ok i have done that but it is still not working?
void putc(unsigned char c)
{
#pragma asm
* Transmit character in A via TXD line
*
MOV DPTR,#c?441
MOV A,R7
MOVX @DPTR,A
putc CLR TXD Drop line for start bit
MOV R0,#BITTIM Wait full bit-time
DJNZ R0,* For START bit
MOV R1,#8 Send 8 bits
putc1 RRC A Move next bit into carry
MOV TXD,C Write next bit
MOV R0,#BITTIM Wait full bit-time
DJNZ R0,* For DATA bit
DJNZ R1,putc1 write 8 bits
SETB TXD Set line high
RRC A Restore ACC contents
MOV R0,#BITTIM Wait full bit-time
DJNZ R0,* For STOP bit
RET
*
#pragma endasm
}
these are the new lines that were created:
MOV DPTR,#c?441
MOV A,R7
MOVX @DPTR,A
|
|
Read-Only Author erik malund Posted 18-Apr-2007 09:44 Toolset C51 |  hardware? erik malund my UARTS have failed ....... but it is still not working What do you connect to? if it is a 232 port (PC) is your MAX232(equivalent) working? if it is a modem (at TTL level or 232) do you know that in that case many are documented and labelled so tx connect to tx? Tell the whole story, till that is known discussing your code is immaterial. Erik |
|
Read-Only Author leigh griffiths Posted 18-Apr-2007 09:47 Toolset C51 |  RE: hardware? leigh griffiths no it is not hardware,im using the max232. i have only one working board, the other i was previously working and does not work with the same code that works on the other. the UART really seems to have failed and thus need a software version to show in a presentation next week :-s |
|
Read-Only Author erik malund Posted 18-Apr-2007 10:27 Toolset C51 |  RE: hardware? erik malund if you blew the Rx or Tx pins you can not use them for a soft UART either. the UART really seems to have failed and thus need a software version to show in a presentation next week is saving $5 more impportant than meeting the deadline? GO SPEND $5 and get a new chip instesd of mucking around with this. Erik |
|
Read-Only Author Andy Neil Posted 18-Apr-2007 10:59 Toolset C51 |  Wrong approach! Andy Neil "i have only one working board, the other i was previously working and does not work with the same code that works on the other." you really need to fix the underlying problem here - throwing in more untried and untested software into an already unreliable system is a really bad idea!! "need a software version to show in a presentation next week" On a deadline like that, now is most certainly not the time to start mucking about with software uarts! You cannot buy extra time - but you can buy a new chip! |
|
Read-Only Author Andy Neil Posted 18-Apr-2007 12:04 Toolset C51 |  RE: hardware? Andy Neil "im using the max232" You're using a MAX232 and you've still managed to blow up the UART?! The MAX232 should protect against most abuse - so if you've blown the UART you must have done something pretty drastic!! :-0 If that's the case, it's even less likely that the rest of the chip is undamaged... |
|
Read-Only Author Per Westermark Posted 18-Apr-2007 15:15 Toolset C51 |  RE: hardware? Per Westermark An excellent method of killing a UART despite the use of a MAX232 is to kill it _with_ the MAX232 - just reverse inputs and outputs on the MAX232 ;) |
|
Read-Only Author Andy Neil Posted 18-Apr-2007 15:29 Toolset C51 |  MAX232 UART Killer Andy Neil You must have a very twisted mind... |
|
Read-Only Author erik malund Posted 18-Apr-2007 15:36 Toolset C51 |  RE: MAX232 UART Killer erik malund I think the reverse |
|
Read-Only Author Andy Neil Posted 18-Apr-2007 11:04 Toolset C51 |  RE: Don't do it in 'C'!! Andy Neil "ok i have done that" No, you haven't - you still have inline assembler in your 'C' source. Go back and follow the 5 steps. Read: http://www.keil.com/support/docs/1671.htm Is this something you really want to be starting from scratch with only a week until your presentation...?! :-0 |
|
Read-Only Author Neil Kurzman Posted 18-Apr-2007 18:53 Toolset C51 |  RE: Don't do it in 'C'!! Neil Kurzman No not with #pragma asm create a file containg only this: void putc(unsigned char c) { } when you compile it as previously directed the compiler will generate an empty c calable asm subroutine. rename the file to .A51 remove the origional from the project. add your ASM code to the new empty ASM subroutine Add the new A51 file to you project then done. |
|