📄 main.c
字号:
state_lcd = STATE_LCD_20; // same sequence-state is repeated
i++;
}
else
{
i=0;
state_lcd = STATE_LCD_21; // next sequence-state is initialised
}
break;
case STATE_LCD_21: // -------- all digits are off
lcd_1 = LCD_OFF;
lcd_2 = LCD_OFF;
lcd_3 = LCD_OFF;
lcd_4 = LCD_OFF;
lcd_5 = LCD_OFF;
lcd_6 = LCD_OFF;
lcd_7 = LCD_OFF;
lcd_8 = LCD_OFF;
state_lcd = STATE_LCD_22; // next sequence-state is initialised
break;
case STATE_LCD_22: // --M16C-- is initialised
lcd_1 = LCD_OFF;
lcd_2 = LCD_OFF;
lcd_3 = LCD_M;
lcd_4 = LCD_1;
lcd_5 = LCD_6;
lcd_6 = LCD_C;
lcd_7 = LCD_OFF;
lcd_8 = LCD_OFF;
if(i<4)
{
state_lcd = STATE_LCD_21; // previous sequence-state is initialised 4 times
i++;
}
else
{
state_lcd = STATE_LCD_23; // next sequence-state is initialised
i=0;
}
break;
case STATE_LCD_23: // 1-2-3-4- is initialised
lcd_1 = LCD_1;
lcd_2 = LCD_OFF;
lcd_3 = LCD_2;
lcd_4 = LCD_OFF;
lcd_5 = LCD_3;
lcd_6 = LCD_OFF;
lcd_7 = LCD_4;
lcd_8 = LCD_OFF;
state_lcd = STATE_LCD_24; // next sequence-state is initialised
break;
case STATE_LCD_24: //-5-6-7-8 is initialised
lcd_1 = LCD_OFF;
lcd_2 = LCD_5;
lcd_3 = LCD_OFF;
lcd_4 = LCD_6;
lcd_5 = LCD_OFF;
lcd_6 = LCD_7;
lcd_7 = LCD_OFF;
lcd_8 = LCD_8;
state_lcd = STATE_LCD_25; // next sequence-state is initialised
break;
case STATE_LCD_25: // from here on every digit is initialised with '9'
lcd_1 = LCD_9; // an counts down to '0' in every following sequence-state.
lcd_2 = LCD_9;
lcd_3 = LCD_9;
lcd_4 = LCD_9;
lcd_5 = LCD_9;
lcd_6 = LCD_9;
lcd_7 = LCD_9;
lcd_8 = LCD_9;
state_lcd = STATE_LCD_26;
break;
case STATE_LCD_26:
lcd_1 = LCD_8;
lcd_2 = LCD_8;
lcd_3 = LCD_8;
lcd_4 = LCD_8;
lcd_5 = LCD_8;
lcd_6 = LCD_8;
lcd_7 = LCD_8;
lcd_8 = LCD_8;
state_lcd = STATE_LCD_27;
break;
case STATE_LCD_27:
lcd_1 = LCD_7;
lcd_2 = LCD_7;
lcd_3 = LCD_7;
lcd_4 = LCD_7;
lcd_5 = LCD_7;
lcd_6 = LCD_7;
lcd_7 = LCD_7;
lcd_8 = LCD_7;
state_lcd = STATE_LCD_28;
break;
case STATE_LCD_28:
lcd_1 = LCD_6;
lcd_2 = LCD_6;
lcd_3 = LCD_6;
lcd_4 = LCD_6;
lcd_5 = LCD_6;
lcd_6 = LCD_6;
lcd_7 = LCD_6;
lcd_8 = LCD_6;
state_lcd = STATE_LCD_29;
break;
case STATE_LCD_29:
lcd_1 = LCD_5;
lcd_2 = LCD_5;
lcd_3 = LCD_5;
lcd_4 = LCD_5;
lcd_5 = LCD_5;
lcd_6 = LCD_5;
lcd_7 = LCD_5;
lcd_8 = LCD_5;
state_lcd = STATE_LCD_30;
break;
case STATE_LCD_30:
lcd_1 = LCD_0;
lcd_2 = LCD_1;
lcd_3 = LCD_1;
lcd_4 = LCD_0;
lcd_5 = LCD_1;
lcd_6 = LCD_1;
lcd_7 = LCD_0;
lcd_8 = LCD_1;
// state_lcd = STATE_LCD_31;
break;
case STATE_LCD_31:
lcd_1 = LCD_3;
lcd_2 = LCD_3;
lcd_3 = LCD_3;
lcd_4 = LCD_3;
lcd_5 = LCD_3;
lcd_6 = LCD_3;
lcd_7 = LCD_3;
lcd_8 = LCD_3;
state_lcd = STATE_LCD_32;
break;
case STATE_LCD_32:
lcd_1 = LCD_2;
lcd_2 = LCD_2;
lcd_3 = LCD_2;
lcd_4 = LCD_2;
lcd_5 = LCD_2;
lcd_6 = LCD_2;
lcd_7 = LCD_2;
lcd_8 = LCD_2;
state_lcd = STATE_LCD_33;
break;
case STATE_LCD_33:
lcd_1 = LCD_1;
lcd_2 = LCD_1;
lcd_3 = LCD_1;
lcd_4 = LCD_1;
lcd_5 = LCD_1;
lcd_6 = LCD_1;
lcd_7 = LCD_1;
lcd_8 = LCD_1;
state_lcd = STATE_LCD_34;
break;
case STATE_LCD_34:
lcd_1 = LCD_0;
lcd_2 = LCD_0;
lcd_3 = LCD_0;
lcd_4 = LCD_0;
lcd_5 = LCD_0;
lcd_6 = LCD_0;
lcd_7 = LCD_0;
lcd_8 = LCD_0;
state_lcd = STATE_LCD_35;
break;
case STATE_LCD_35:
lcd_1 = LCD_OFF;
lcd_2 = LCD_OFF;
lcd_3 = LCD_OFF;
lcd_4 = LCD_OFF;
lcd_5 = LCD_OFF;
lcd_6 = LCD_OFF;
lcd_7 = LCD_OFF;
lcd_8 = LCD_OFF;
state_lcd = STATE_LCD_OFF;
break;
default:
state_lcd = STATE_LCD_OFF;
break;
}
lcd_1 = lcd_1 + RDS;
lcd_10 = LCD_D10_2;
ms++;
if ((ms&1)== 0)
lcd_10 = lcd_10 + D10_col;
if (ms >= 60)
ms = 0;
lcd_11 = LCD_D11_1;
lcd_12 = LCD_D12_2;
/* calculate port data for port 1 and 2*/
/* Port 1 controls digit 1 and 2 */
/* Port 2 controls digit 3 and 4 */
/* All digits can be initialised with the follwing 'common'/'segment' line combinations: */
/* Example for the first digit */
/* C3 C2 C1 C0 */
/* ---- ---- ---- ---- */
/* |||| |||| |||| |||+-------------- SEG 1 (bit0) */
/* |||| |||| |||| ||+--------------- SEG 2 (bit1 */
/* |||| |||| |||| |+---------------- SEG 3 (bit2) */
/* |||| |||| |||| +----------------- SEG 4 (bit3) */
/* |||| |||| |||+--------------------- SEG 1 (bit4) */
/* |||| |||| ||+---------------------- SEG 2 (bit5) */
/* |||| |||| |+----------------------- SEG 3 (bit6) */
/* |||| |||| +------------------------ SEG 4 (bit7) */
/* |||| |||+---------------------------- SEG 1 (bit8) */
/* |||| ||+----------------------------- SEG 2 (bit9) */
/* |||| |+------------------------------ SEG 3 (bit10)*/
/* |||| +------------------------------- SEG 4 (bit11)*/
/* |||+----------------------------------- SEG 1 (bit12)*/
/* ||+------------------------------------ SEG 2 (bit13)*/
/* |+------------------------------------- SEG 3 (bit14)*/
/* +-------------------------------------- SEG 4 (bit15)*/
/* C0 controled by P0.0 */
/* C1 controled by P0.1 */
/* C2 controled by P0.2 */
/* C3 controled by P0.3 */
/* SEG1 controled by P1.0 */
/* SEG2 controled by P1.1 */
/* SEG2 controled by P1.2 */
/* SEG3 controled by P1.3 */
/* initialisation of port-buffer 'port_1_c0' and 'port_2_c0' for common-state C0 */
buf = (unsigned char)(lcd_1&0x000F);
buf |= (unsigned char)((lcd_2&0x000F)<<4);
port_1_c0 = buf;
buf = (unsigned char)(lcd_3&0x000F);
buf |= (unsigned char)((lcd_4&0x000F)<<4);
port_2_c0 = buf;
/* initialisation of port-buffer 'port_1_c1' and 'port_2_c1' for common-state C1 */
buf = (unsigned char)((lcd_1&0x00F0)>>4);
buf |= (unsigned char)(lcd_2&0x00F0);
port_1_c1 = buf;
buf = (unsigned char)((lcd_3&0x00F0)>>4);
buf |= (unsigned char)(lcd_4&0x00F0);
port_2_c1 = buf;
/* initialisation of port-buffer 'port_1_c2' and 'port_2_c2' for common-state C2 */
buf = (unsigned char)((lcd_1&0x0F00)>>8);
buf |= (unsigned char)((lcd_2&0x0F00)>>4);
port_1_c2 = buf;
buf = (unsigned char)((lcd_3&0x0F00)>>8);
buf |= (unsigned char)((lcd_4&0x0F00)>>4);
port_2_c2 = buf;
/* initialisation of port-buffer 'port_1_c3' and 'port_2_c3' for common-state C3 */
buf = (unsigned char)((lcd_1&0xF000)>>12);
buf |= (unsigned char)((lcd_2&0xF000)>>8);
port_1_c3 = buf;
buf = (unsigned char)((lcd_3&0xF000)>>12);
buf |= (unsigned char)((lcd_4&0xF000)>>8);
port_2_c3 = buf;
/* calculate port data for port 3 and 5 */
/* Port 3 controls digit 5 and 6 */
/* Port 5 controls digit 7 and 8 */
/* initialisation of port-buffer 'port_3_c0' and 'port_5_c0' for common-state C0 */
buf = (unsigned char)(lcd_5&0x000F);
buf |= (unsigned char)((lcd_6&0x000F)<<4);
port_3_c0 = buf;
buf = (unsigned char)(lcd_7&0x000F);
buf |= (unsigned char)((lcd_8&0x000F)<<4);
buf |= (unsigned char)((lcd_9&0x0008)<<4);
port_4_c0 = buf;
/* initialisation of port-buffer 'port_3_c1' and 'port_5_c1' for common-state C1 */
buf = (unsigned char)((lcd_5&0x00F0)>>4);
buf |= (unsigned char)(lcd_6&0x00F0);
port_3_c1 = buf;
buf = (unsigned char)((lcd_7&0x00F0)>>4);
buf |= (unsigned char)(lcd_8&0x00F0);
port_4_c1 = buf;
/* initialisation of port-buffer 'port_3_c2' and 'port_5_c2' for common-state C2 */
buf = (unsigned char)((lcd_5&0x0F00)>>8);
buf |= (unsigned char)((lcd_6&0x0F00)>>4);
port_3_c2 = buf;
buf = (unsigned char)((lcd_7&0x0F00)>>8);
buf |= (unsigned char)((lcd_8&0x0F00)>>4);
port_4_c2 = buf;
/* initialisation of port-buffer 'port_3_c3' and 'port_5_c3' for common-state C3 */
buf = (unsigned char)((lcd_5&0xF000)>>12);
buf |= (unsigned char)((lcd_6&0xF000)>>8);
port_3_c3 = buf;
buf = (unsigned char)((lcd_7&0xF000)>>12);
buf |= (unsigned char)((lcd_8&0xF000)>>8);
port_4_c3 = buf;
/* initialisation of port-buffer 'port_3_c0' and 'port_5_c0' for common-state C0 */
buf = (unsigned char)(lcd_10&0x000F);
buf |= (unsigned char)((lcd_11&0x0003)<<4);
buf |= (unsigned char)((lcd_12&0x000C)<<4);
port_5_c0 = buf;
/* initialisation of port-buffer 'port_3_c1' and 'port_5_c1' for common-state C1 */
buf = (unsigned char)((lcd_10&0x00F0)>>4);
buf |= (unsigned char)(lcd_11&0x0030);
buf |= (unsigned char)(lcd_12&0x00C0);
port_5_c1 = buf;
/* initialisation of port-buffer 'port_3_c2' and 'port_5_c2' for common-state C2 */
buf = (unsigned char)((lcd_10&0x0F00)>>8);
buf |= (unsigned char)((lcd_11&0x0300)>>4);
buf |= (unsigned char)((lcd_12&0x0C00)>>4);
port_5_c2 = buf;
/* initialisation of port-buffer 'port_3_c3' and 'port_5_c3' for common-state C3 */
buf = (unsigned char)((lcd_10&0xF000)>>12);
buf |= (unsigned char)((lcd_11&0x3000)>>8);
buf |= (unsigned char)((lcd_12&0xC000)>>8);
port_5_c3 = buf;
}
}
} //main end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -