⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ks0108test.lss

📁 for ks0108 LCD Controller
💻 LSS
📖 第 1 页 / 共 5 页
字号:
			ks0108PutChar(pgm_read_byte(str));
		}
		str++;
	}
}

uint8_t ks0108CharWidth(char c) {
     4c4:	0f 93       	push	r16
     4c6:	1f 93       	push	r17
     4c8:	08 2f       	mov	r16, r24
	uint8_t width = 0;
	uint8_t firstChar = ks0108FontRead(ks0108Font+FONT_FIRST_CHAR);
     4ca:	80 91 67 00 	lds	r24, 0x0067
     4ce:	90 91 68 00 	lds	r25, 0x0068
     4d2:	e0 91 65 00 	lds	r30, 0x0065
     4d6:	f0 91 66 00 	lds	r31, 0x0066
     4da:	04 96       	adiw	r24, 0x04	; 4
     4dc:	09 95       	icall
     4de:	18 2f       	mov	r17, r24
	uint8_t charCount = ks0108FontRead(ks0108Font+FONT_CHAR_COUNT);
     4e0:	80 91 67 00 	lds	r24, 0x0067
     4e4:	90 91 68 00 	lds	r25, 0x0068
     4e8:	e0 91 65 00 	lds	r30, 0x0065
     4ec:	f0 91 66 00 	lds	r31, 0x0066
     4f0:	05 96       	adiw	r24, 0x05	; 5
     4f2:	09 95       	icall
	
	// read width data
	if(c >= firstChar && c < (firstChar+charCount)) {
     4f4:	01 17       	cp	r16, r17
     4f6:	b8 f0       	brcs	.+46     	; 0x526 <ks0108CharWidth+0x62>
     4f8:	20 2f       	mov	r18, r16
     4fa:	33 27       	eor	r19, r19
     4fc:	81 0f       	add	r24, r17
     4fe:	91 2d       	mov	r25, r1
     500:	91 1d       	adc	r25, r1
     502:	28 17       	cp	r18, r24
     504:	39 07       	cpc	r19, r25
     506:	7c f4       	brge	.+30     	; 0x526 <ks0108CharWidth+0x62>
		c -= firstChar;
		width = ks0108FontRead(ks0108Font+FONT_WIDTH_TABLE+c)+1;
     508:	01 1b       	sub	r16, r17
     50a:	80 91 67 00 	lds	r24, 0x0067
     50e:	90 91 68 00 	lds	r25, 0x0068
     512:	80 0f       	add	r24, r16
     514:	91 1d       	adc	r25, r1
     516:	e0 91 65 00 	lds	r30, 0x0065
     51a:	f0 91 66 00 	lds	r31, 0x0066
     51e:	06 96       	adiw	r24, 0x06	; 6
     520:	09 95       	icall
     522:	8f 5f       	subi	r24, 0xFF	; 255
     524:	01 c0       	rjmp	.+2      	; 0x528 <ks0108CharWidth+0x64>
     526:	80 e0       	ldi	r24, 0x00	; 0
	}
	
	return width;
}
     528:	99 27       	eor	r25, r25
     52a:	1f 91       	pop	r17
     52c:	0f 91       	pop	r16
     52e:	08 95       	ret

00000530 <ks0108StringWidth>:

uint16_t ks0108StringWidth(char* str) {
     530:	0f 93       	push	r16
     532:	1f 93       	push	r17
     534:	cf 93       	push	r28
     536:	df 93       	push	r29
     538:	ec 01       	movw	r28, r24
     53a:	00 e0       	ldi	r16, 0x00	; 0
     53c:	10 e0       	ldi	r17, 0x00	; 0
     53e:	04 c0       	rjmp	.+8      	; 0x548 <ks0108StringWidth+0x18>
	uint16_t width = 0;
	
	while(*str != 0) {
		width += ks0108CharWidth(*str++);
     540:	21 96       	adiw	r28, 0x01	; 1
     542:	c0 df       	rcall	.-128    	; 0x4c4 <ks0108CharWidth>
     544:	08 0f       	add	r16, r24
     546:	11 1d       	adc	r17, r1
     548:	88 81       	ld	r24, Y
     54a:	88 23       	and	r24, r24
     54c:	c9 f7       	brne	.-14     	; 0x540 <ks0108StringWidth+0x10>
	}
	
	return width;
}
     54e:	c8 01       	movw	r24, r16
     550:	df 91       	pop	r29
     552:	cf 91       	pop	r28
     554:	1f 91       	pop	r17
     556:	0f 91       	pop	r16
     558:	08 95       	ret

0000055a <ks0108StringWidth_P>:

uint16_t ks0108StringWidth_P(PGM_P str) {
     55a:	0f 93       	push	r16
     55c:	1f 93       	push	r17
     55e:	cf 93       	push	r28
     560:	df 93       	push	r29
     562:	ec 01       	movw	r28, r24
     564:	00 e0       	ldi	r16, 0x00	; 0
     566:	10 e0       	ldi	r17, 0x00	; 0
     568:	06 c0       	rjmp	.+12     	; 0x576 <ks0108StringWidth_P+0x1c>
	uint16_t width = 0;
	
	while(pgm_read_byte(str) != 0) {
		width += ks0108CharWidth(pgm_read_byte(str++));
     56a:	21 96       	adiw	r28, 0x01	; 1
     56c:	f9 01       	movw	r30, r18
     56e:	84 91       	lpm	r24, Z
     570:	a9 df       	rcall	.-174    	; 0x4c4 <ks0108CharWidth>
     572:	08 0f       	add	r16, r24
     574:	11 1d       	adc	r17, r1
     576:	9e 01       	movw	r18, r28
     578:	fe 01       	movw	r30, r28
     57a:	84 91       	lpm	r24, Z
     57c:	88 23       	and	r24, r24
     57e:	a9 f7       	brne	.-22     	; 0x56a <ks0108StringWidth_P+0x10>
	}
	
	return width;
}
     580:	c8 01       	movw	r24, r16
     582:	df 91       	pop	r29
     584:	cf 91       	pop	r28
     586:	1f 91       	pop	r17
     588:	0f 91       	pop	r16
     58a:	08 95       	ret

0000058c <ks0108Enable>:

void ks0108GotoXY(uint8_t x, uint8_t y) {
	uint8_t chip = CHIP1, cmd;
	
	if(x > 127) x = 0;								// ensure that coordinates are legal
	if(y > 63)  y = 0;
	
	ks0108Coord.x = x;								// save new coordinates
	ks0108Coord.y = y;
	ks0108Coord.page = y/8;
	
	if(x >= 64) {									// select the right chip
		x -= 64;
		chip = CHIP2;
	}
	cmd = LCD_SET_ADD | x;
	ks0108WriteCommand(cmd, chip);					// set x address on active chip
	
	cmd = LCD_SET_PAGE | ks0108Coord.page;			// set y address on both chips
	ks0108WriteCommand(cmd, CHIP1);
	ks0108WriteCommand(cmd, CHIP2);
}

void ks0108Init(uint8_t invert) {
	ks0108Coord.x = 0;
	ks0108Coord.y = 0;
	ks0108Coord.page = 0;
	
	ks0108Inverted = invert;
	
	LCD_CMD_DIR = 0xFF;								// command port is output
	ks0108WriteCommand(LCD_ON, CHIP1);				// power on
	ks0108WriteCommand(LCD_ON, CHIP2);
	
	ks0108WriteCommand(LCD_DISP_START, CHIP1);		// display start line = 0
	ks0108WriteCommand(LCD_DISP_START, CHIP2);
	ks0108ClearScreen();							// display clear
	ks0108GotoXY(0,0);
}

inline void ks0108Enable(void) {
     58c:	cf 93       	push	r28
     58e:	df 93       	push	r29
     590:	cd b7       	in	r28, 0x3d	; 61
     592:	de b7       	in	r29, 0x3e	; 62
     594:	21 97       	sbiw	r28, 0x01	; 1
     596:	0f b6       	in	r0, 0x3f	; 63
     598:	f8 94       	cli
     59a:	de bf       	out	0x3e, r29	; 62
     59c:	0f be       	out	0x3f, r0	; 63
     59e:	cd bf       	out	0x3d, r28	; 61
	LCD_CMD_PORT |= 0x01 << EN;						// EN high level width: min. 450ns
     5a0:	aa 9a       	sbi	0x15, 2	; 21
	asm volatile("nop\n\t"
     5a2:	00 00       	nop
     5a4:	00 00       	nop
     5a6:	00 00       	nop
				 "nop\n\t"
				 "nop\n\t"
				 ::);
	LCD_CMD_PORT &= ~(0x01 << EN);
     5a8:	aa 98       	cbi	0x15, 2	; 21
	for(volatile uint8_t i=0; i<8; i++);			// a little delay loop (faster than reading the busy flag)
     5aa:	19 82       	std	Y+1, r1	; 0x01
     5ac:	03 c0       	rjmp	.+6      	; 0x5b4 <ks0108Enable+0x28>
     5ae:	89 81       	ldd	r24, Y+1	; 0x01
     5b0:	8f 5f       	subi	r24, 0xFF	; 255
     5b2:	89 83       	std	Y+1, r24	; 0x01
     5b4:	89 81       	ldd	r24, Y+1	; 0x01
     5b6:	88 30       	cpi	r24, 0x08	; 8
     5b8:	d0 f3       	brcs	.-12     	; 0x5ae <ks0108Enable+0x22>
     5ba:	21 96       	adiw	r28, 0x01	; 1
     5bc:	0f b6       	in	r0, 0x3f	; 63
     5be:	f8 94       	cli
     5c0:	de bf       	out	0x3e, r29	; 62
     5c2:	0f be       	out	0x3f, r0	; 63
     5c4:	cd bf       	out	0x3d, r28	; 61
     5c6:	df 91       	pop	r29
     5c8:	cf 91       	pop	r28
     5ca:	08 95       	ret

000005cc <ks0108WriteCommand>:
}

uint8_t ks0108DoReadData(uint8_t first) {
	uint8_t data;
	volatile uint8_t i;
	
	LCD_DATA_OUT = 0x00;
	LCD_DATA_DIR = 0x00;							// data port is input
	
	if(ks0108Coord.x < 64) {
		LCD_CMD_PORT &= ~(0x01 << CSEL2);			// deselect chip 2
		LCD_CMD_PORT |= 0x01 << CSEL1;				// select chip 1
	} else if(ks0108Coord.x >= 64) {
		LCD_CMD_PORT &= ~(0x01 << CSEL1);			// deselect chip 1
		LCD_CMD_PORT |= 0x01 << CSEL2;				// select chip 2
	}
	if(ks0108Coord.x == 64 && first) {				// chip2 X-address = 0
		ks0108WriteCommand(LCD_SET_ADD, CHIP2); 	// wuff wuff
	}
	
	LCD_CMD_PORT |= 0x01 << D_I;					// D/I = 1
	LCD_CMD_PORT |= 0x01 << R_W;					// R/W = 1
	
	LCD_CMD_PORT |= 0x01 << EN;						// EN high level width: min. 450ns
	asm volatile("nop\n\t"
				 "nop\n\t"
				 "nop\n\t"
				 ::);
	
	data = LCD_DATA_IN;								// read Data			 
	
	LCD_CMD_PORT &= ~(0x01 << EN);
	for(i=0; i<8; i++);								// a little delay loop (faster than reading the busy flag)
	
	LCD_DATA_DIR = 0xFF;
	
	ks0108GotoXY(ks0108Coord.x, ks0108Coord.y);
	
	if(ks0108Inverted)
		data = ~data;
	return data;
}

inline uint8_t ks0108ReadData(void) {
	ks0108DoReadData(1);							// dummy read
	return ks0108DoReadData(0);						// "real" read
}

void ks0108WriteCommand(uint8_t cmd, uint8_t chip) {
     5cc:	98 2f       	mov	r25, r24
	if(chip == CHIP1) {
     5ce:	66 23       	and	r22, r22
     5d0:	19 f4       	brne	.+6      	; 0x5d8 <ks0108WriteCommand+0xc>
		LCD_CMD_PORT &= ~(0x01 << CSEL2);			// deselect chip 2
     5d2:	ac 98       	cbi	0x15, 4	; 21
		LCD_CMD_PORT |= 0x01 << CSEL1;				// select chip 1
     5d4:	ab 9a       	sbi	0x15, 3	; 21
     5d6:	04 c0       	rjmp	.+8      	; 0x5e0 <ks0108WriteCommand+0x14>
	} else if(chip == CHIP2) {
     5d8:	61 30       	cpi	r22, 0x01	; 1
     5da:	11 f4       	brne	.+4      	; 0x5e0 <ks0108WriteCommand+0x14>
		LCD_CMD_PORT &= ~(0x01 << CSEL1);			// deselect chip 1
     5dc:	ab 98       	cbi	0x15, 3	; 21
		LCD_CMD_PORT |= 0x01 << CSEL2;				// select chip 2
     5de:	ac 9a       	sbi	0x15, 4	; 21
	}
	
	LCD_CMD_PORT &= ~(0x01 << D_I);					// D/I = 0
     5e0:	a8 98       	cbi	0x15, 0	; 21
	LCD_CMD_PORT &= ~(0x01 << R_W);					// R/W = 0
     5e2:	a9 98       	cbi	0x15, 1	; 21
	LCD_DATA_DIR = 0xFF;							// data port is output
     5e4:	8f ef       	ldi	r24, 0xFF	; 255
     5e6:	81 bb       	out	0x11, r24	; 17
	LCD_DATA_OUT = cmd;								// write command
     5e8:	92 bb       	out	0x12, r25	; 18
	ks0108Enable();									// enable
     5ea:	d0 df       	rcall	.-96     	; 0x58c <ks0108Enable>
	LCD_DATA_OUT = 0x00;
     5ec:	12 ba       	out	0x12, r1	; 18
     5ee:	08 95       	ret

000005f0 <ks0108GotoXY>:
     5f0:	1f 93       	push	r17
     5f2:	87 fd       	sbrc	r24, 7
     5f4:	80 e0       	ldi	r24, 0x00	; 0
     5f6:	60 34       	cpi	r22, 0x40	; 64
     5f8:	08 f0       	brcs	.+2      	; 0x5fc <ks0108GotoXY+0xc>
     5fa:	60 e0       	ldi	r22, 0x00	; 0
     5fc:	80 93 62 00 	sts	0x0062, r24
     600:	60 93 63 00 	sts	0x0063, r22
     604:	66 95       	lsr	r22
     606:	66 95       	lsr	r22
     608:	66 95       	lsr	r22
     60a:	60 93 64 00 	sts	0x0064, r22
     60e:	80 34       	cpi	r24, 0x40	; 64
     610:	10 f4       	brcc	.+4      	; 0x616 <ks0108GotoXY+0x26>
     612:	60 e0       	ldi	r22, 0x00	; 0
     614:	02 c0       	rjmp	.+4      	; 0x61a <ks0108GotoXY+0x2a>
     616:	80 54       	subi	r24, 0x40	; 64
     618:	61 e0       	ldi	r22, 0x01	; 1
     61a:	80 64       	ori	r24, 0x40	; 64
     61c:	d7 df       	rcall	.-82     	; 0x5cc <ks0108WriteCommand>
     61e:	10 91 64 00 	lds	r17, 0x0064
     622:	18 6b       	ori	r17, 0xB8	; 184
     624:	60 e0       	ldi	r22, 0x00	; 0
     626:	81 2f       	mov	r24, r17
     628:	d1 df       	rcall	.-94     	; 0x5cc <ks0108WriteCommand>
     62a:	61 e0       	ldi	r22, 0x01	; 1
     62c:	81 2f       	mov	r24, r17
     62e:	ce df       	rcall	.-100    	; 0x5cc <ks0108WriteCommand>
     630:	1f 91       	pop	r17
     632:	08 95       	ret

00000634 <ks0108DoReadData>:
     634:	1f 93       	push	r17
     636:	cf 93       	push	r28
     638:	df 93       	push	r29

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -