📄 main.lss
字号:
// 为printf和getkey输入输出初始化串口
int uart_putchar( char c, FILE *stream )
{
596: 1f 93 push r17
598: 18 2f mov r17, r24
if (c == '\n') uart_putchar( '\r', stream );
59a: 8a 30 cpi r24, 0x0A ; 10
59c: 19 f0 breq .+6 ; 0x5a4 <uart_putchar+0xe>
while ( ( UCSR0A & ( 1 << UDRE ) ) == 0 );
59e: 5d 9b sbis 0x0b, 5 ; 11
5a0: fe cf rjmp .-4 ; 0x59e <uart_putchar+0x8>
5a2: 04 c0 rjmp .+8 ; 0x5ac <uart_putchar+0x16>
5a4: 8d e0 ldi r24, 0x0D ; 13
5a6: 0e 94 cb 02 call 0x596 ; 0x596 <uart_putchar>
5aa: f9 cf rjmp .-14 ; 0x59e <uart_putchar+0x8>
UDR0 = c;
5ac: 1c b9 out 0x0c, r17 ; 12
return 0;
}
5ae: 80 e0 ldi r24, 0x00 ; 0
5b0: 90 e0 ldi r25, 0x00 ; 0
5b2: 1f 91 pop r17
5b4: 08 95 ret
000005b6 <mInitSTDIO>:
FILE uart_str = FDEV_SETUP_STREAM( uart_putchar, NULL, _FDEV_SETUP_WRITE );
void mInitSTDIO( void )
{
5b6: 10 92 90 00 sts 0x0090, r1
UBRR0H = 0;//UBRR0H = 0;
UBRR0L = 5;//UBRR0L = 103; // 115200bps@11.0592MHz
5ba: 85 e0 ldi r24, 0x05 ; 5
5bc: 89 b9 out 0x09, r24 ; 9
UCSR0B = 0x18;//UCSR0B = 0x18; // BIT(RXEN) | BIT(TXEN);
5be: 88 e1 ldi r24, 0x18 ; 24
5c0: 8a b9 out 0x0a, r24 ; 10
UCSR0C = 0x06;//UCSR0C = 0x06; // BIT(UCSZ1) | BIT(UCSZ0);
5c2: 86 e0 ldi r24, 0x06 ; 6
5c4: 80 93 95 00 sts 0x0095, r24
stdout = stdin = &uart_str;
5c8: 88 e6 ldi r24, 0x68 ; 104
5ca: 91 e0 ldi r25, 0x01 ; 1
5cc: 90 93 bc 01 sts 0x01BC, r25
5d0: 80 93 bb 01 sts 0x01BB, r24
5d4: 90 93 be 01 sts 0x01BE, r25
5d8: 80 93 bd 01 sts 0x01BD, r24
5dc: 08 95 ret
000005de <set_usb_mode>:
5de: ff 92 push r15
5e0: 0f 93 push r16
5e2: 1f 93 push r17
5e4: cf 93 push r28
5e6: df 93 push r29
5e8: f8 2e mov r15, r24
5ea: 85 e1 ldi r24, 0x15 ; 21
5ec: 0e 94 65 00 call 0xca ; 0xca <xWriteCH375Cmd>
5f0: 8f 2d mov r24, r15
5f2: 0e 94 74 00 call 0xe8 ; 0xe8 <xWriteCH375Data>
*/
void
_delay_loop_2(uint16_t __count)
{
__asm__ volatile (
5f6: 89 e9 ldi r24, 0x99 ; 153
5f8: 95 e1 ldi r25, 0x15 ; 21
5fa: 01 97 sbiw r24, 0x01 ; 1
5fc: f1 f7 brne .-4 ; 0x5fa <set_usb_mode+0x1c>
5fe: 00 e0 ldi r16, 0x00 ; 0
600: 11 e0 ldi r17, 0x01 ; 1
602: c0 e0 ldi r28, 0x00 ; 0
604: d0 e0 ldi r29, 0x00 ; 0
606: 09 c0 rjmp .+18 ; 0x61a <set_usb_mode+0x3c>
608: 1f 93 push r17
60a: 0f 93 push r16
60c: 0e 94 98 03 call 0x730 ; 0x730 <printf>
*/
void
_delay_loop_2(uint16_t __count)
{
__asm__ volatile (
610: ce 01 movw r24, r28
612: 01 97 sbiw r24, 0x01 ; 1
614: f1 f7 brne .-4 ; 0x612 <set_usb_mode+0x34>
616: 0f 90 pop r0
618: 0f 90 pop r0
61a: 0e 94 83 00 call 0x106 ; 0x106 <xReadCH375Data>
61e: 81 35 cpi r24, 0x51 ; 81
620: 99 f7 brne .-26 ; 0x608 <set_usb_mode+0x2a>
622: 8f 2d mov r24, r15
624: 99 27 eor r25, r25
626: 9f 93 push r25
628: 8f 93 push r24
62a: 86 e1 ldi r24, 0x16 ; 22
62c: 91 e0 ldi r25, 0x01 ; 1
62e: 9f 93 push r25
630: 8f 93 push r24
632: 0e 94 98 03 call 0x730 ; 0x730 <printf>
636: 0f 90 pop r0
638: 0f 90 pop r0
63a: 0f 90 pop r0
63c: 0f 90 pop r0
63e: 81 e0 ldi r24, 0x01 ; 1
640: 90 e0 ldi r25, 0x00 ; 0
642: df 91 pop r29
644: cf 91 pop r28
646: 1f 91 pop r17
648: 0f 91 pop r16
64a: ff 90 pop r15
64c: 08 95 ret
0000064e <main>:
}
// 主机端的主程序简单示例
int main( void )
{
64e: ef 92 push r14
650: ff 92 push r15
652: 0f 93 push r16
654: 1f 93 push r17
656: cf 93 push r28
658: df 93 push r29
65a: cd b7 in r28, 0x3d ; 61
65c: de b7 in r29, 0x3e ; 62
65e: 68 97 sbiw r28, 0x18 ; 24
660: 0f b6 in r0, 0x3f ; 63
662: f8 94 cli
664: de bf out 0x3e, r29 ; 62
666: 0f be out 0x3f, r0 ; 63
668: cd bf out 0x3d, r28 ; 61
// unsigned char xdata data_to_send[200]; // 缓冲区
unsigned char str_to_print[]="OK, support text print\n";
66a: 7e 01 movw r14, r28
66c: 08 94 sec
66e: e1 1c adc r14, r1
670: f1 1c adc r15, r1
672: d7 01 movw r26, r14
674: e0 e5 ldi r30, 0x50 ; 80
676: f1 e0 ldi r31, 0x01 ; 1
678: 88 e1 ldi r24, 0x18 ; 24
67a: 01 90 ld r0, Z+
67c: 0d 92 st X+, r0
67e: 81 50 subi r24, 0x01 ; 1
680: e1 f7 brne .-8 ; 0x67a <main+0x2c>
unsigned char s;
MCUCR = 0x80; //外部RAM使能
682: 80 e8 ldi r24, 0x80 ; 128
684: 85 bf out 0x35, r24 ; 53
EICRA=0xFF; //INT0的上升沿产生异步中断请求
686: 8f ef ldi r24, 0xFF ; 255
688: 80 93 6a 00 sts 0x006A, r24
EIMSK=0x02; //使能外部中断
68c: 82 e0 ldi r24, 0x02 ; 2
68e: 89 bf out 0x39, r24 ; 57
*/
void
_delay_loop_2(uint16_t __count)
{
__asm__ volatile (
690: 80 e0 ldi r24, 0x00 ; 0
692: 90 e0 ldi r25, 0x00 ; 0
694: 01 97 sbiw r24, 0x01 ; 1
696: f1 f7 brne .-4 ; 0x694 <main+0x46>
mDelaymS( 200 );
mInitSTDIO( );
698: 0e 94 db 02 call 0x5b6 ; 0x5b6 <mInitSTDIO>
printf("hello world\n\r");
69c: 8b e2 ldi r24, 0x2B ; 43
69e: 91 e0 ldi r25, 0x01 ; 1
6a0: 9f 93 push r25
6a2: 8f 93 push r24
6a4: 0e 94 98 03 call 0x730 ; 0x730 <printf>
set_usb_mode( 6 ); // 设置USB主机模式
6a8: 86 e0 ldi r24, 0x06 ; 6
6aa: 0e 94 ef 02 call 0x5de ; 0x5de <set_usb_mode>
6ae: 0f 90 pop r0
6b0: 0f 90 pop r0
while ( wait_interrupt()!=USB_INT_CONNECT ); // 等待USB打印机连接上来
6b2: 0e 94 90 00 call 0x120 ; 0x120 <wait_interrupt>
6b6: 85 31 cpi r24, 0x15 ; 21
6b8: e1 f7 brne .-8 ; 0x6b2 <main+0x64>
// 如果设备端是CH341转打印口或者是CH37X,那么以下步骤是可选的,如果是其它USB芯片,那么可能需要执行以下步骤
#define USB_RESET_FIRST 1 // USB规范中未要求在USB设备插入后必须复位该设备,但是计算机的WINDOWS总是这样做,所以有些USB设备也要求在插入后必须先复位才能工作
#ifdef USB_RESET_FIRST
set_usb_mode( 7 ); // 复位USB设备,CH375向USB信号线的D+和D-输出低电平
6ba: 87 e0 ldi r24, 0x07 ; 7
6bc: 0e 94 ef 02 call 0x5de ; 0x5de <set_usb_mode>
*/
void
_delay_loop_2(uint16_t __count)
{
__asm__ volatile (
6c0: 80 e0 ldi r24, 0x00 ; 0
6c2: 9c e6 ldi r25, 0x6C ; 108
6c4: 01 97 sbiw r24, 0x01 ; 1
6c6: f1 f7 brne .-4 ; 0x6c4 <main+0x76>
// 如果单片机对CH375的INT#引脚采用中断方式而不是查询方式,那么应该在复制USB设备期间禁止CH375中断,在USB设备复位完成后清除CH375中断标志再允许中断
mDelaymS( 10 ); // 复位时间不少于1mS,建议为10mS
set_usb_mode( 6 ); // 结束复位
6c8: 86 e0 ldi r24, 0x06 ; 6
6ca: 0e 94 ef 02 call 0x5de ; 0x5de <set_usb_mode>
*/
void
_delay_loop_2(uint16_t __count)
{
__asm__ volatile (
6ce: 80 e0 ldi r24, 0x00 ; 0
6d0: 90 e0 ldi r25, 0x00 ; 0
6d2: 01 97 sbiw r24, 0x01 ; 1
6d4: f1 f7 brne .-4 ; 0x6d2 <main+0x84>
mDelaymS( 100 );
while ( wait_interrupt()!=USB_INT_CONNECT ); // 等待复位之后的设备端再次连接上来
6d6: 0e 94 90 00 call 0x120 ; 0x120 <wait_interrupt>
6da: 85 31 cpi r24, 0x15 ; 21
6dc: e1 f7 brne .-8 ; 0x6d6 <main+0x88>
*/
void
_delay_loop_2(uint16_t __count)
{
__asm__ volatile (
6de: 80 e0 ldi r24, 0x00 ; 0
6e0: 90 e0 ldi r25, 0x00 ; 0
6e2: 01 97 sbiw r24, 0x01 ; 1
6e4: f1 f7 brne .-4 ; 0x6e2 <main+0x94>
#endif
mDelaymS( 200 ); // 有些USB设备要等待数百毫秒才能正常工作
if ( init_print()!=USB_INT_SUCCESS ) while(1); // 错误
6e6: 0e 94 52 02 call 0x4a4 ; 0x4a4 <init_print>
6ea: 84 31 cpi r24, 0x14 ; 20
6ec: 91 f0 breq .+36 ; 0x712 <main+0xc4>
6ee: ff cf rjmp .-2 ; 0x6ee <main+0xa0>
while ( 1 ) {
s = get_port_status( );
if ( s!=0xFF ) {
if ( s&0x20 ) printf("No paper!\n");
6f0: 89 e3 ldi r24, 0x39 ; 57
6f2: 91 e0 ldi r25, 0x01 ; 1
6f4: 0e 94 b8 03 call 0x770 ; 0x770 <puts>
if ( (s&0x08) == 0 ) printf("Print ERROR!\n");
6f8: 03 ff sbrs r16, 3
6fa: 15 c0 rjmp .+42 ; 0x726 <main+0xd8>
}
send_data( strlen(str_to_print), str_to_print ); // 输出数据给打印机,与通过并口方式输出一样
6fc: f7 01 movw r30, r14
6fe: 01 90 ld r0, Z+
700: 00 20 and r0, r0
702: e9 f7 brne .-6 ; 0x6fe <main+0xb0>
704: 31 97 sbiw r30, 0x01 ; 1
706: b7 01 movw r22, r14
708: cf 01 movw r24, r30
70a: 8e 19 sub r24, r14
70c: 9f 09 sbc r25, r15
70e: 0e 94 60 01 call 0x2c0 ; 0x2c0 <send_data>
712: 0e 94 9f 01 call 0x33e ; 0x33e <get_port_status>
716: 8f 3f cpi r24, 0xFF ; 255
718: 89 f3 breq .-30 ; 0x6fc <main+0xae>
71a: 08 2f mov r16, r24
71c: 11 27 eor r17, r17
71e: 05 fd sbrc r16, 5
720: e7 cf rjmp .-50 ; 0x6f0 <main+0xa2>
722: 03 fd sbrc r16, 3
724: eb cf rjmp .-42 ; 0x6fc <main+0xae>
726: 83 e4 ldi r24, 0x43 ; 67
728: 91 e0 ldi r25, 0x01 ; 1
72a: 0e 94 b8 03 call 0x770 ; 0x770 <puts>
72e: e6 cf rjmp .-52 ; 0x6fc <main+0xae>
00000730 <printf>:
730: cf 93 push r28
732: df 93 push r29
734: cd b7 in r28, 0x3d ; 61
736: de b7 in r29, 0x3e ; 62
738: 22 97 sbiw r28, 0x02 ; 2
73a: 0f b6 in r0, 0x3f ; 63
73c: f8 94 cli
73e: de bf out 0x3e, r29 ; 62
740: 0f be out 0x3f, r0 ; 63
742: cd bf out 0x3d, r28 ; 61
744: fe 01 movw r30, r28
746: 37 96 adiw r30, 0x07 ; 7
748: 61 91 ld r22, Z+
74a: 71 91 ld r23, Z+
74c: fa 83 std Y+2, r31 ; 0x02
74e: e9 83 std Y+1, r30 ; 0x01
750: af 01 movw r20, r30
752: 80 91 bd 01 lds r24, 0x01BD
756: 90 91 be 01 lds r25, 0x01BE
75a: 0e 94 eb 03 call 0x7d6 ; 0x7d6 <vfprintf>
75e: 22 96 adiw r28, 0x02 ; 2
760: 0f b6 in r0, 0x3f ; 63
762: f8 94 cli
764: de bf out 0x3e, r29 ; 62
766: 0f be out 0x3f, r0 ; 63
768: cd bf out 0x3d, r28 ; 61
76a: df 91 pop r29
76c: cf 91 pop r28
76e: 08 95 ret
00000770 <puts>:
770: 0f 93 push r16
772: 1f 93 push r17
774: cf 93 push r28
776: df 93 push r29
778: 8c 01 movw r16, r24
77a: e0 91 bd 01 lds r30, 0x01BD
77e: f0 91 be 01 lds r31, 0x01BE
782: 83 81 ldd r24, Z+3 ; 0x03
784: 81 ff sbrs r24, 1
786: 1f c0 rjmp .+62 ; 0x7c6 <puts+0x56>
788: c0 e0 ldi r28, 0x00 ; 0
78a: d0 e0 ldi r29, 0x00 ; 0
78c: 0a c0 rjmp .+20 ; 0x7a2 <puts+0x32>
78e: fd 01 movw r30, r26
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -