-
- /************************************************************
- FileName: ui.c
- Author: 原野之狼
- Version :V1.0
- Date: 2009.12.18
- Description:
-
- History:
- <author> <time> <version > <desc>
- ************************************************************/
- #include "includes.h"
- //define the 8 segments of the number led in the window.
- //you can modify these datas by considerating the architecture of the numer led
- //and the hardware connections.
- //here the architecture of led in the main window is different with the led in the vice window.
- //define the 8 segments of the number led in the main window.
- #define SEG_A 0X40
- #define SEG_B 0X80
- #define SEG_C 0X04
- #define SEG_D 0X10
- #define SEG_E 0X08
- #define SEG_F 0X01
- #define SEG_G 0X20
- #define SEG_DP 0X02
- //define the 8 segments of the number led in the vice window.
- #define SEG_A_ 0X02
- #define SEG_B_ 0X04
- #define SEG_C_ 0X08
- #define SEG_D_ 0X80
- #define SEG_E_ 0X40
- #define SEG_F_ 0X10
- #define SEG_G_ 0X20
- #define SEG_DP_ 0X01
- //define the segment code of the number in the main window
- static const prog_uchar code_num[] = {
- SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F, // 0
- SEG_B | SEG_C, // 1
- SEG_A | SEG_B | SEG_D | SEG_E | SEG_G, // 2
- SEG_A | SEG_B | SEG_C | SEG_D | SEG_G, // 3
- SEG_B | SEG_C | SEG_F | SEG_G, // 4
- SEG_A | SEG_F | SEG_G | SEG_C | SEG_D, // 5
- SEG_A | SEG_F | SEG_E | SEG_D | SEG_C | SEG_G, // 6
- SEG_A | SEG_B | SEG_C, // 7
- SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F | SEG_G, // 8
- SEG_A | SEG_B | SEG_C | SEG_D | SEG_F | SEG_G // 9
- };
- //define the segment code of the letters
- static const prog_uchar code_letter[]={
- SEG_A | SEG_B | SEG_C | SEG_E | SEG_F | SEG_G, // a
- SEG_C | SEG_D | SEG_E | SEG_F | SEG_G, // b
- SEG_A | SEG_D | SEG_E | SEG_F, // c
- SEG_B | SEG_C | SEG_D | SEG_E | SEG_G, // d
- SEG_A | SEG_D | SEG_E | SEG_F | SEG_G, // e
- SEG_A | SEG_E | SEG_F | SEG_G, // f
- SEG_A | SEG_B | SEG_C | SEG_D | SEG_F | SEG_G, // g
- SEG_B | SEG_C | SEG_E | SEG_F | SEG_G, // h
- SEG_E | SEG_F, // i
- SEG_B | SEG_C | SEG_D | SEG_E, // j
- SEG_B | SEG_D | SEG_E | SEG_F | SEG_G, // k
- SEG_D | SEG_E | SEG_F, // l
- SEG_A | SEG_C | SEG_E | SEG_G, // m
- SEG_C | SEG_E | SEG_G, // n
- SEG_C | SEG_D | SEG_E | SEG_G, // o
- SEG_A | SEG_B | SEG_E | SEG_F | SEG_G, // p
- SEG_A | SEG_B | SEG_C | SEG_F | SEG_G, // q
- SEG_E | SEG_G, // r
- SEG_A | SEG_F | SEG_G | SEG_C | SEG_D, // s
- SEG_D | SEG_E | SEG_F | SEG_G, // t
- SEG_B | SEG_C | SEG_D | SEG_E | SEG_F, // u
- SEG_C | SEG_D | SEG_E, // v
- SEG_B | SEG_D | SEG_F | SEG_G, // w
- SEG_B | SEG_C | SEG_E | SEG_F, // x
- SEG_B | SEG_C | SEG_D | SEG_F | SEG_G, // y
- SEG_A | SEG_D | SEG_G // z
- };
- static const prog_uchar code_null =0x00; // ' '
- static const prog_uchar code_bar = SEG_G; // '-'
- static const prog_uchar code_dp = SEG_DP; // '.'
- //display buf
- //10 for number leds. 1 one for leds
- UINT8 display_buf[11];
- /***********************************************************
- Description:
- intial the display sys
-
- Modify Record:
-
- ***********************************************************/
- void display_init(void)
- {
- UINT8 i;
-
- DDRE |=0xc0; // set B9&B10 output
- DDRB |=0x01; // set B11 output
- for (i = 0; i < 11; i++)
- {
- display_buf[i] = 0x00;
- }
- init_595();
- timer2_init();
- timer2_start();
- }
- /***********************************************************
- Description:
- scan the led.
- this function should be called by a timer at least every 20ms/11.
-
- Modify Record:
-
- ***********************************************************/
- void led_scan_run(void)
- {
- /***********************************************
- main window:
- ---- ---- ---- ---- ----
- | | | | | | | | | |
- ---- ---- ---- ---- ----
- | | | | | | | | | |
- ---- ---- ---- ---- ----
- pos: 4 3 2 1 0
- bit sel:
- 5 4 ...
- buf map:
- buf[0] ...
- vice window:
- ---- ---- ---- ---- ----
- | | | | | | | | | |
- ---- ---- ---- ---- ----
- | | | | | | | | | |
- ---- ---- ---- ---- ----
- pos: 9 8 7 6 5
- bit sel:
- 9 8 ...
- bif map:
- buf[5] ...
- led:
- @ @ @ @
- led4 led3 led2 led1
- pos: 10
- bit sel:
- 10
- buf[10]
- ***********************************************/
- static UINT8 pos = 0;
- switch (pos)
- {
- case 0:
- {
- B9_LOW;
- B10_LOW;
- B11_LOW;
- driver_595(display_buf[4], 0x04);
- }
- break;
- case 1:
- {
- B9_LOW;
- B10_LOW;
- B11_LOW;
- driver_595(display_buf[3], 0x02);
- }
- break;
- case 2:
- {
- B9_LOW;
- B10_LOW;
- B11_LOW;
- driver_595(display_buf[2], 0x08);
- }
- break;
- case 3:
- {
- B9_LOW;
- B10_LOW;
- B11_LOW;
- driver_595(display_buf[1], 0x10);
- }
- break;
- case 4:
- {
- B9_LOW;
- B10_LOW;
- B11_LOW;
- driver_595(display_buf[0], 0x01);
- }
- break;
- case 5:
- {
- B9_LOW;
- B10_LOW;
- B11_LOW;
- driver_595(display_buf[9], 0x20);
- }
- break;
- case 6:
- {
- B9_LOW;
- B10_LOW;
- B11_LOW;
- driver_595(display_buf[8], 0x40);
- }
- break;
- case 7:
- {
- B9_LOW;
- B10_LOW;
- B11_LOW;
- driver_595(display_buf[7], 0x80);
- }
- break;
- case 8:
- {
- B10_LOW;
- B11_LOW;
- driver_595(display_buf[6], 0x00);
- B9_HIGH;
- }
- break;
- case 9:
- {
- B9_LOW;
- B11_LOW;
- driver_595(display_buf[5], 0x00);
- B10_HIGH;
- }
- break;
- case 10:
- {
- B9_LOW;
- B10_LOW;
- driver_595(display_buf[10], 0x00);
- B11_HIGH;
- }
- break;
- default:
- asm("nop");
- }
- pos++;
- pos %= 11;
- }
- /***********************************************************
- Description:
- display contents in the main window
- Input:
- contens in char.
- for example:
- 99.999
- abcde
- sys-1
- 8.8.8.8.8.
-
- Others:
- for safety considerations,the input para must be checked.
- but not done here.
-
- Modify Record:
-
- ***********************************************************/
- void display_main(char *p)
- {
- UINT8 i = 0,j = 0;
- do
- {
- if (*(p + i) >= '0' && *(p + i) <= '9')
- {
- cli();
- display_buf[j++] = pgm_read_byte(&code_num[*(p + i) - '0']);
- sei();
- }
- if (*(p + i) >= 'a' && *(p + i) <= 'z')
- {
- cli();
- display_buf[j++] = pgm_read_byte(&code_letter[*(p + i) - 'a']);
- sei();
- }
- if (*(p + i) == ' ')
- {
- cli();
- display_buf[j++] = pgm_read_byte(&code_null);
- sei();
- }
- if (*(p + i) == '.')
- {
- cli();
- display_buf[j -1] |= pgm_read_byte(&code_dp);
- sei();
- }
-
- if (*(p + i) == '-')
- {
- cli();
- display_buf[j++] = pgm_read_byte(&code_bar);
- sei();
- }
- i++;
- } while (*(p + i));
- }