查看: 1537|回复: 4
|
Programming 求助
[复制链接]
|
|
比如说我有8bits of data.
data=0b10111100。
我想display 1st 4bit of data, then 2nd lower 4bit of data.
我用 PIC16F84A, PortA 只有4个I/O port.
要怎么能:
1。PortA=upper 4 bit of data.
2。Display Port A
3。PortA=lower 4 bit of data.
4。Display Port A
请用C language 来教我。 |
|
|
|
|
|
|
|
发表于 12-3-2006 07:23 PM
|
显示全部楼层
原帖由 南极星 于 12-3-2006 05:51 PM 发表
比如说我有8bits of data.
data=0b10111100。
我想display 1st 4bit of data, then 2nd lower 4bit of data.
我用 PIC16F84A, PortA 只有4个I/O port.
要怎么能:
1。PortA=upper 4 bit of data.
...
- void display_binary(char c)
- {
- char i;
- i = 8;
- putc('0');
- putc('b');
- do
- {
- if( c & 0x80 )
- { putc('1'); }
- else
- { putc('0'); }
- c <<= 1; i--;
- } while(i);
- }
复制代码
*************************OR***************************
- //======================= Main ==============================
- void main(void)
- {
- int8 data=180;//180=0xB4=1011 0100
- printf(bin_putc,"This is a test %lX\n\r",data);
- while(1)
- {
- }
- }
- //======================= print binary nibbles from hex ============================//
- void bin_putc( char c) {
- //converts hex to bin
- //printf(bin_putc,"%lX\n\r",data);
- switch (c) {
- case '0' :
- fprintf(DEBUG,"0000 ");
- break;
- case '1' :
- fprintf(DEBUG,"0001 ");
- break;
- case '2' :
- fprintf(DEBUG,"0010 ");
- break;
- case '3' :
- fprintf(DEBUG,"0011 ");
- break;
- case '4' :
- fprintf(DEBUG,"0100 ");
- break;
- case '5' :
- fprintf(DEBUG,"0101 ");
- break;
- case '6' :
- fprintf(DEBUG,"0110 ");
- break;
- case '7' :
- fprintf(DEBUG,"0111 ");
- break;
- case '8' :
- fprintf(DEBUG,"1000 ");
- break;
- case '9' :
- fprintf(DEBUG,"1001 ");
- break;
- case 'A' || 'a' :
- fprintf(DEBUG,"1010 ");
- break;
- case 'B' || 'b' :
- fprintf(DEBUG,"1011 ");
- break;
- case 'C' || 'c' :
- fprintf(DEBUG,"1100 ");
- break;
- case 'D' || 'd' :
- fprintf(DEBUG,"1101 ");
- break;
- case 'E' || 'e' :
- fprintf(DEBUG,"1110 ");
- break;
- case 'F' || 'f' :
- fprintf(DEBUG,"1111 ");
- break;
- default :
- fprintf(DEBUG,"%C",c);
- break;
- }
- }
复制代码
[ 本帖最后由 hi--520 于 12-3-2006 07:25 PM 编辑 ] |
|
|
|
|
|
|
|
发表于 12-3-2006 07:30 PM
|
显示全部楼层
原帖由 南极星 于 12-3-2006 05:51 PM 发表
比如说我有8bits of data.
data=0b10111100。
我想display 1st 4bit of data, then 2nd lower 4bit of data.
我用 PIC16F84A, PortA 只有4个I/O port.
要怎么能:
1。PortA=upper 4 bit of data.
...
1。PortA=upper 4 bit of data.
PortA=data>>4; // Shift 4bit right to get MSB
2。Display Port A
3。PortA=lower 4 bit of data.
PortA=data & 0b00001111; // Mask lower 4 bit to get LSB
4。Display Port A |
|
|
|
|
|
|
|
发表于 13-3-2006 05:34 PM
|
显示全部楼层
1。PortA=upper 4 bit of data.
PortA=data>>4; // Shift 4bit right to get MSB
2。Display Port A
3。PortA=lower 4 bit of data.
PortA=data & 0b00001111; // Mask lower 4 bit to get LSB
4。Display Port A
2and 4 之后放一个1sec delay比较好!!
mcu太快了,我怕你的眼睛看不到 |
|
|
|
|
|
|
|
楼主 |
发表于 14-3-2006 12:32 AM
|
显示全部楼层
谢谢各位大哥大姐回复。 此恩难忘 |
|
|
|
|
|
|
| |
本周最热论坛帖子
|