📄 main.ls
字号:
1 ; C Compiler for STM8 (COSMIC Software)
2 ; Parser V4.8.32.1 - 30 Mar 2010
3 ; Generator V4.3.4 - 23 Mar 2010
2823 ; 52 void delay_ms(u16 ms)
2823 ; 53 {
2825 switch .text
2826 0000 _delay_ms:
2828 0000 89 pushw x
2829 0001 88 push a
2830 00000001 OFST: set 1
2833 0002 201b jra L1102
2834 0004 L7002:
2835 ; 57 for(i=0;i<250;i++)
2837 0004 0f01 clr (OFST+0,sp)
2838 0006 L5102:
2841 0006 0c01 inc (OFST+0,sp)
2844 0008 7b01 ld a,(OFST+0,sp)
2845 000a a1fa cp a,#250
2846 000c 25f8 jrult L5102
2847 ; 59 for(i=0;i<75;i++)
2849 000e 0f01 clr (OFST+0,sp)
2850 0010 L3202:
2853 0010 0c01 inc (OFST+0,sp)
2856 0012 7b01 ld a,(OFST+0,sp)
2857 0014 a14b cp a,#75
2858 0016 25f8 jrult L3202
2859 ; 61 ms--;
2861 0018 1e02 ldw x,(OFST+1,sp)
2862 001a 1d0001 subw x,#1
2863 001d 1f02 ldw (OFST+1,sp),x
2864 001f L1102:
2865 ; 55 while(ms!=0)
2867 001f 1e02 ldw x,(OFST+1,sp)
2868 0021 26e1 jrne L7002
2869 ; 63 }
2872 0023 5b03 addw sp,#3
2873 0025 81 ret
2916 ; 65 void delay_us(u16 us)
2916 ; 66 {
2917 switch .text
2918 0026 _delay_us:
2920 0026 89 pushw x
2921 0027 88 push a
2922 00000001 OFST: set 1
2925 0028 201b jra L5502
2926 002a L3502:
2927 ; 70 for(i=0;i<25;i++)
2929 002a 0f01 clr (OFST+0,sp)
2930 002c L1602:
2933 002c 0c01 inc (OFST+0,sp)
2936 002e 7b01 ld a,(OFST+0,sp)
2937 0030 a119 cp a,#25
2938 0032 25f8 jrult L1602
2939 ; 72 for(i=0;i<7;i++)
2941 0034 0f01 clr (OFST+0,sp)
2942 0036 L7602:
2945 0036 0c01 inc (OFST+0,sp)
2948 0038 7b01 ld a,(OFST+0,sp)
2949 003a a107 cp a,#7
2950 003c 25f8 jrult L7602
2951 ; 74 us--;
2953 003e 1e02 ldw x,(OFST+1,sp)
2954 0040 1d0001 subw x,#1
2955 0043 1f02 ldw (OFST+1,sp),x
2956 0045 L5502:
2957 ; 68 while(us!=0)
2959 0045 1e02 ldw x,(OFST+1,sp)
2960 0047 26e1 jrne L3502
2961 ; 76 }
2964 0049 5b03 addw sp,#3
2965 004b 81 ret
3011 ; 18 void I2C_Init(void)
3011 ; 19 {
3012 switch .text
3013 004c _I2C_Init:
3017 ; 20 I2C_FREQR=0x0f; //设置频率寄存器
3019 004c 350f5212 mov _I2C_FREQR,#15
3020 ; 21 I2C_CCRH=0x00; //设置始终寄存器高位
3022 0050 725f521c clr _I2C_CCRH
3023 ; 22 I2C_CCRL=0x50; //设置始终寄存器低位
3025 0054 3550521b mov _I2C_CCRL,#80
3026 ; 23 I2C_TRISER=0x11; //设置最大SCL上升时间
3028 0058 3511521d mov _I2C_TRISER,#17
3029 ; 24 I2C_CR1|=0x01; //使能I2C模块
3031 005c 72105210 bset _I2C_CR1,#0
3032 ; 25 I2C_Ack(); //设置匹配应答
3034 0060 72145211 bset _I2C_CR2,#2
3035 ; 26 I2C_CR2|=0x08; //设置接收应答
3038 0064 72165211 bset _I2C_CR2,#3
3039 ; 27 }
3042 0068 81 ret
3068 ; 30 void I2C_Start(void)
3068 ; 31 {
3069 switch .text
3070 0069 _I2C_Start:
3074 0069 L5212:
3075 ; 32 I2C_busy();
3077 0069 c65219 ld a,_I2C_SR3
3078 006c a402 and a,#2
3079 006e a101 cp a,#1
3080 0070 27f7 jreq L5212
3081 ; 33 I2C_start();
3084 0072 72105211 bset _I2C_CR2,#0
3087 0076 L3312:
3088 ; 34 while(I2C_SBask==0);
3090 0076 c65217 ld a,_I2C_SR1
3091 0079 a501 bcp a,#1
3092 007b 27f9 jreq L3312
3093 ; 35 }
3096 007d 81 ret
3133 ; 37 void I2C_SendDAdr(u8 Add)
3133 ; 38 {
3134 switch .text
3135 007e _I2C_SendDAdr:
3139 ; 39 I2C_writebyte(Add);
3141 007e c75216 ld _I2C_DR,a
3144 0081 L7512:
3145 ; 40 while(I2C_addrask==0);
3147 0081 c65217 ld a,_I2C_SR1
3148 0084 a502 bcp a,#2
3149 0086 27f9 jreq L7512
3151 0088 L5612:
3152 ; 41 I2C_busy();
3154 0088 c65219 ld a,_I2C_SR3
3155 008b a402 and a,#2
3156 008d a101 cp a,#1
3157 008f 27f7 jreq L5612
3158 ; 42 }
3162 0091 81 ret
3199 ; 45 void I2C_SendDat(u8 data)
3199 ; 46 {
3200 switch .text
3201 0092 _I2C_SendDat:
3205 ; 47 I2C_writebyte(data);
3207 0092 c75216 ld _I2C_DR,a
3210 0095 L1122:
3211 ; 48 I2C_busy();
3213 0095 c65219 ld a,_I2C_SR3
3214 0098 a402 and a,#2
3215 009a a101 cp a,#1
3216 009c 27f7 jreq L1122
3219 009e L7122:
3220 ; 49 while(I2C_TxEask==0);
3222 009e c65217 ld a,_I2C_SR1
3223 00a1 a580 bcp a,#128
3224 00a3 27f9 jreq L7122
3225 ; 50 }
3228 00a5 81 ret
3264 ; 52 u8 I2C_RcvDat(void)
3264 ; 53 {
3265 switch .text
3266 00a6 _I2C_RcvDat:
3268 00a6 88 push a
3269 00000001 OFST: set 1
3272 00a7 L5422:
3273 ; 55 while(I2C_RxNeask==0);
3275 00a7 c65217 ld a,_I2C_SR1
3276 00aa a540 bcp a,#64
3277 00ac 27f9 jreq L5422
3278 00ae L3222:
3279 ; 56 abc:
3279 ; 57 if(I2C_BTF==0x04)
3281 00ae c65217 ld a,_I2C_SR1
3282 00b1 a404 and a,#4
3283 00b3 a104 cp a,#4
3284 00b5 26f7 jrne L3222
3285 ; 58 {i=I2C_DR;}
3287 00b7 c65216 ld a,_I2C_DR
3288 00ba 6b01 ld (OFST+0,sp),a
3290 ; 60 if(I2C_BTF==0){}
3292 00bc c65217 ld a,_I2C_SR1
3293 00bf a504 bcp a,#4
3294 00c1 26eb jrne L3222
3296 ; 62 return i;
3298 00c3 7b01 ld a,(OFST+0,sp)
3301 00c5 5b01 addw sp,#1
3302 00c7 81 ret
3357 ; 42 void PCF8591_WriteAByte(u8 dat)
3357 ; 43 {
3358 switch .text
3359 00c8 _PCF8591_WriteAByte:
3361 00c8 88 push a
3362 00000000 OFST: set 0
3365 ; 44 I2C_Start();
3367 00c9 ad9e call _I2C_Start
3369 ; 45 I2C_SendDAdr(WD_DADR);
3371 00cb a690 ld a,#144
3372 00cd adaf call _I2C_SendDAdr
3374 ; 46 I2C_SendDat(dat);
3376 00cf 7b01 ld a,(OFST+1,sp)
3377 00d1 adbf call _I2C_SendDat
3379 ; 47 I2C_stop();
3381 00d3 72125211 bset _I2C_CR2,#1
3382 ; 48 }
3386 00d7 84 pop a
3387 00d8 81 ret
3425 ; 50 u8 PCF8591_ReadAByte(void)
3425 ; 51 {
3426 switch .text
3427 00d9 _PCF8591_ReadAByte:
3429 00d9 88 push a
3430 00000001 OFST: set 1
3433 ; 53 I2C_Start();
3435 00da ad8d call _I2C_Start
3437 ; 54 I2C_NAck();
3439 00dc 72155211 bres _I2C_CR2,#2
3440 ; 55 I2C_SendDAdr(RD_DADR);
3443 00e0 a691 ld a,#145
3444 00e2 ad9a call _I2C_SendDAdr
3446 ; 56 dat=I2C_RcvDat();
3448 00e4 adc0 call _I2C_RcvDat
3450 00e6 6b01 ld (OFST+0,sp),a
3451 ; 57 I2C_stop();
3453 00e8 72125211 bset _I2C_CR2,#1
3454 ; 58 I2C_Ack();
3457 00ec 72145211 bset _I2C_CR2,#2
3458 ; 59 return dat;
3461 00f0 7b01 ld a,(OFST+0,sp)
3464 00f2 5b01 addw sp,#1
3465 00f4 81 ret
3520 ; 62 void PCF8591_getAD(u8 mode,u8 chan,u8 *ADC)
3520 ; 63 {
3521 switch .text
3522 00f5 _PCF8591_getAD:
3524 00f5 89 pushw x
3525 00000000 OFST: set 0
3528 ; 64 PCF8591_WriteAByte(mode|chan);
3530 00f6 9f ld a,xl
3531 00f7 1a01 or a,(OFST+1,sp)
3532 00f9 adcd call _PCF8591_WriteAByte
3534 ; 65 ADC[0]=PCF8591_ReadAByte();
3536 00fb addc call _PCF8591_ReadAByte
3538 00fd 1e05 ldw x,(OFST+5,sp)
3539 00ff f7 ld (x),a
3540 ; 66 }
3543 0100 85 popw x
3544 0101 81 ret
3586 ; 17 void SPI_Init(void)
3586 ; 18 {
3587 switch .text
3588 0102 _SPI_Init:
3592 ; 19 SPI_CR1|=0x38; //波特率
3594 0102 c65200 ld a,_SPI_CR1
3595 0105 aa38 or a,#56
3596 0107 c75200 ld _SPI_CR1,a
3597 ; 24 SPI_CR2|=0x03; //配置NSS脚为1
3599 010a c65201 ld a,_SPI_CR2
3600 010d aa03 or a,#3
3601 010f c75201 ld _SPI_CR2,a
3602 ; 25 SPI_CR1|=0x04; //配置为主设备
3604 0112 72145200 bset _SPI_CR1,#2
3605 ; 26 SPI_CR1|=0x40; //开启SPI
3607 0116 721c5200 bset _SPI_CR1,#6
3608 ; 27 }
3611 011a 81 ret
3647 ; 29 void SPI_sendchar(u8 data)
3647 ; 30 {
3648 switch .text
3649 011b _SPI_sendchar:
3653 ; 31 SPI_DR=data;
3655 011b c75204 ld _SPI_DR,a
3657 011e L1142:
3658 ; 32 while(!(SPI_SR & 0x02));
3660 011e c65203 ld a,_SPI_SR
3661 0121 a502 bcp a,#2
3662 0123 27f9 jreq L1142
3663 ; 33 }
3666 0125 81 ret
3702 ; 35 u8 SPI_rechar(void)
3702 ; 36 {
3703 switch .text
3704 0126 _SPI_rechar:
3706 0126 88 push a
3707 00000001 OFST: set 1
3710 ; 38 data=SPI_DR;
3712 0127 c65204 ld a,_SPI_DR
3713 012a 6b01 ld (OFST+0,sp),a
3715 012c L7342:
3716 ; 39 while(!(SPI_SR & 0x01));
3718 012c c65203 ld a,_SPI_SR
3719 012f a501 bcp a,#1
3720 0131 27f9 jreq L7342
3721 ; 40 return data;
3723 0133 7b01 ld a,(OFST+0,sp)
3726 0135 5b01 addw sp,#1
3727 0137 81 ret
3786 ; 21 void st7920LcdInit(void)
3786 ; 22 {
3787 switch .text
3788 0138 _st7920LcdInit:
3790 0138 88 push a
3791 00000001 OFST: set 1
3794 ; 24 SPI_Init();
3796 0139 adc7 call _SPI_Init
3798 ; 25 delay_ms(100);
3800 013b ae0064 ldw x,#100
3801 013e cd0000 call _delay_ms
3803 ; 26 PE_DDR|=0x20;
3805 0141 721a5016 bset _PE_DDR,#5
3806 ; 27 PE_CR1|=0x20;
3808 0145 721a5017 bset _PE_CR1,#5
3809 ; 28 PE_CR2|=0x20;
3811 0149 721a5018 bset _PE_CR2,#5
3812 ; 29 sendCodeST7920(0x0c);//整体显示
3814 014d a60c ld a,#12
3815 014f ad1c call _sendCodeST7920
3817 ; 30 sendCodeST7920(0x01);//清屏
3819 0151 a601 ld a,#1
3820 0153 ad18 call _sendCodeST7920
3822 ; 31 sendCodeST7920(0x02);
3824 0155 a602 ld a,#2
3825 0157 ad14 call _sendCodeST7920
3827 ; 32 for(i=0;i<64;i++)
3829 0159 0f01 clr (OFST+0,sp)
3830 015b L7642:
3831 ; 33 lcd_buffer[i]=' ';
3833 015b 7b01 ld a,(OFST+0,sp)
3834 015d 5f clrw x
3835 015e 97 ld xl,a
3836 015f a620 ld a,#32
3837 0161 e700 ld (_lcd_buffer,x),a
3838 ; 32 for(i=0;i<64;i++)
3840 0163 0c01 inc (OFST+0,sp)
3843 0165 7b01 ld a,(OFST+0,sp)
3844 0167 a140 cp a,#64
3845 0169 25f0 jrult L7642
3846 ; 35 }
3849 016b 84 pop a
3850 016c 81 ret
3887 ; 37 void sendCodeST7920(u8 Lcd_cmd)
3887 ; 38 {
3888 switch .text
3889 016d _sendCodeST7920:
3891 016d 88 push a
3892 00000000 OFST: set 0
3895 ; 39 E_CLK
3897 016e 721b5014 bres _PE_ODR,#5
3898 ; 40 LCD_DELAY()
3901 0172 9d nop
3906 0173 9d nop
3911 0174 9d nop
3916 0175 9d nop
3921 0176 9d nop
3923 ; 41 E_SET
3925 0177 721a5014 bset _PE_ODR,#5
3926 ; 42 SPI_sendchar(0xF8);
3928 017b a6f8 ld a,#248
3929 017d ad9c call _SPI_sendchar
3931 ; 43 SPI_sendchar(Lcd_cmd & 0xF0);
3933 017f 7b01 ld a,(OFST+1,sp)
3934 0181 a4f0 and a,#240
3935 0183 ad96 call _SPI_sendchar
3937 ; 44 SPI_sendchar(Lcd_cmd << 4);
3939 0185 7b01 ld a,(OFST+1,sp)
3940 0187 97 ld xl,a
3941 0188 a610 ld a,#16
3942 018a 42 mul x,a
3943 018b 9f ld a,xl
3944 018c ad8d call _SPI_sendchar
3946 ; 45 LCD_DELAY()
3949 018e 9d nop
3954 018f 9d nop
3959 0190 9d nop
3964 0191 9d nop
3969 0192 9d nop
3971 ; 46 E_CLK
3973 0193 721b5014 bres _PE_ODR,#5
3974 ; 47 LCD_DELAY()
3977 0197 9d nop
3982 0198 9d nop
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -