AT89C51的输出电流才几百微安,达不到能直接点亮二极管的电流。
二极管一侧接VCC,一侧接C51(1K电阻),当C51输出低电位可以点亮,
但是C51过载(最大容许电流10mA每个port)
高电位实际输出才是几个微安怎么可能亮,除非每个引脚到VCC加5K电阻。
不推荐
IOL = 低电位最大输出电流
Maximum IOL per port pin: 10 mA
Maximum IOL per 8-bit port: Port 0: 26 mA
Ports 1, 2, 3: 15 mA
Maximum total IOL for all output pins: 71 mA
你的SetRow()函数细节是如何,看不清楚。
试试下列程序,看看有否效果。
;//-------------------------
ORG 0000H
ajmp main
org 0100h
main:
mov sp, #70h
MOV 50H, #066H
MOV 51H, #099H
MOV 52H, #081H
MOV 53H, #081H
MOV 54H, #042H
MOV 55H, #024H
MOV 56H, #018H
MOV 57H, #000H
;//-------------------------
ACALL DISP500MS
SJMP $ - 2
;//-------------------------
DISP500MS:
MOV R4, #60
ACALL mainloop
DJNZ R4, $ - 2
RET
;//-------------------------
mainloop:
MOV A, #0FEH
MOV R0, #50H
MOV R5, #8
flashcy:
MOV P1, A
MOV P2, @R0
INC R0
RL A
LCALL DELAY
DJNZ R5, flashcy
RET
;//-------------------------
DELAY: MOV R7, #4
DELAY1: MOV R6, #128
DJNZ R6, $
DJNZ R7,DELAY1
RET
;//-------------------------
end
谢谢你的回答,这是全问源程序,你再帮我看看吧.
刚刚我试了一下您发的代码,不知道是不是我的接线问题,不行.
我的接线是这样的:
P2.x
0 1 2 3 4 5 6 7
| | | | | | | |
+-------------------+
| @ @ @ @ @ @ @ @ |
| @ @ @ @ @ @ @ @ |
| @ @ @ @ @ @ @ @ |
| @ @ @ @ @ @ @ @ |
| @ @ @ @ @ @ @ @ |
| @ @ @ @ @ @ @ @ |
| @ @ @ @ @ @ @ @ |
| @ @ @ @ @ @ @ @ |
+-------------------+
| | | | | | | |
0 1 2 3 4 5 6 7
P1.x
MT12088BR
(描述型号字在这面)
#include
#include
///////////////////////////////////////////////////
// idx | 0 1 2 3 4 5 6 7 //
//-----------------------------------------------//
// row | 04 01 06 00 12 07 10 15 //
// | 0100 0001 0110 0000 1100 0111 1010 1111 //
// | 0x04 0x01 0x06 0x00 0x0C 0x07 0x0A 0x0F //
// P | 0.4 0.1 0.6 0.0 2.4 0.7 2.2 2.7 //
//-----------------------------------------------//
// col | 11 02 03 14 05 13 09 08 //
// | 0x0B 0x02 0x03 0x0E 0x05 0x0D 0x09 0x08 //
// P | 2.3 0.2 0.3 2.6 0.5 2.5 2.1 2.0 //
///////////////////////////////////////////////////
#define DEFINE_PORT(a0,a1,a2,a3,a4,a5,a6,a7) (0x##a7##a6##a5##a4##a3##a2##a1##a0)
const unsigned long code rows = DEFINE_PORT(4,1,6,0,C,7,A,F);
const unsigned long code cols = DEFINE_PORT(B,2,3,E,5,D,9,8);
#define RC(x,y) ( ((x&07)<<3) | ((y)&07) )
const unsigned char code range[] =
{
RC(0,0), RC(0,1), RC(0,2), RC(0,3), RC(0,4), RC(0,5), RC(0,6), RC(0,7)
, RC(1,7), RC(2,7), RC(3,7), RC(4,7), RC(5,7), RC(6,7), RC(7,7), RC(7,6)
, RC(7,5), RC(7,4), RC(7,3), RC(7,2), RC(7,1), RC(7,0), RC(6,0), RC(5,0)
, RC(4,0), RC(3,0), RC(2,0), RC(1,0), RC(1,1), RC(1,2), RC(1,3), RC(1,4)
, RC(1,5), RC(1,6), RC(2,6), RC(3,6), RC(4,6), RC(5,6), RC(6,6), RC(6,5)
, RC(6,4), RC(6,3), RC(6,2), RC(6,1), RC(5,1), RC(4,1), RC(3,1), RC(2,1)
, RC(2,2), RC(2,3), RC(2,4), RC(2,5), RC(3,5), RC(4,5), RC(5,5), RC(5,4)
, RC(5,3), RC(5,2), RC(4,2), RC(3,2), RC(3,3), RC(3,4), RC(4,4), RC(4,3)
};
const unsigned char code range2[][8] =
{
{ 0xff, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xff } ,
{ 0x00, 0x7e, 0x42, 0x42, 0x42, 0x42, 0x7e, 0x00 } ,
{ 0x00, 0x00, 0x3c, 0x24, 0x24, 0x3c, 0x00, 0x00 } ,
{ 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00 } ,
{ 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00 } ,
{ 0x00, 0x00, 0x3c, 0x24, 0x24, 0x3c, 0x00, 0x00 } ,
{ 0x00, 0x7e, 0x42, 0x42, 0x42, 0x42, 0x7e, 0x00 } ,
{ 0xff, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xff }
};
#define GET_ROW_IDX(idx_mask) (((idx_mask)>>3)&07)
#define GET_COL_IDX(idx_mask) ((idx_mask)&07)
#define GET_PORT_MASK(sour,idx) (((sour)>>((idx)*4))&0xf)
#define GET_PORT_BIT(sour,idx) (GET_PORT_MASK(sour,idx)>>3)
#define GET_PORT_DATA(sour,idx) (GET_PORT_MASK(sour,idx)&07)
#define true 1
#define false 0
typedef unsigned char bool;
void SetPort(bool port, unsigned char idx, bool is_light)
{
idx = 1<
if (is_light){ P2 |= idx; }
else{P2 &= ~idx;;}
}
else{
if (is_light){P1 |= idx;}
else{P1 &= ~idx;}
}
}
void SetPoint(unsigned char row,unsigned char col, bool is_light)
{
row = GET_PORT_MASK(rows,row);
col = GET_PORT_MASK(cols,col);
SetPort(row>>3,row&07,is_light);
SetPort(col>>3,col&07,!is_light);
}
void Clear(void)
{
unsigned char c = 8;
unsigned char tmp;
while(c--){
if ( (tmp = GET_PORT_MASK(rows,c)) & 8) {
P2 &= ~(1<<(tmp&07));
}
else{
P1 &= ~(1<<(tmp&07));
}
if ( (tmp = GET_PORT_MASK(cols,c)) & 8) {
P2 |= (1<<(tmp&07));
}
else{
P1 |= (1<<(tmp&07));
}
}
}
void delay( unsigned short times )
{
while(--times);
}
void SetRow( unsigned char row, unsigned char cols_mask, bool is_light )
{
unsigned short idx = 0;
for (; idx<8*sizeof(cols_mask); ++idx) { // col
unsigned char col = GET_PORT_MASK(cols,7u-idx);
if (cols_mask&(1u<
}
else {
SetPort(col>>3,col&07,is_light);
}
}
row = GET_PORT_MASK(rows,row);
SetPort(row>>3,row&07,is_light);
}
void main()
{
char idx = -1;
unsigned char step = 4;
Clear();
// by row OK
while ( idx < sizeof(range)/sizeof(range[0]) )
{
SetPoint(GET_ROW_IDX(idx),GET_COL_IDX(idx),false);
idx++;
SetPoint(GET_ROW_IDX(idx),GET_COL_IDX(idx),true);
delay(0x0fff);
}
SetPoint(GET_ROW_IDX(idx),GET_COL_IDX(idx),false);
idx = -1;
// 转圈 OK
for(step = 16; step<0x40; step<<=1)
{
while ( idx < sizeof(range)/sizeof(range[0])-1 )
{
SetPoint(GET_ROW_IDX(range[idx]),GET_COL_IDX(range[idx]),false);
idx++;
SetPoint(GET_ROW_IDX(range[idx]),GET_COL_IDX(range[idx]),true);
delay(0xffffu/step);
}
while ( idx > 0 )
{
SetPoint(GET_ROW_IDX(range[idx]),GET_COL_IDX(range[idx]),false);
idx--;
SetPoint(GET_ROW_IDX(range[idx]),GET_COL_IDX(range[idx]),true);
delay(0xffffu/step);
}
};
// "口"字型 Faild
while(1)
{
for (step = 0; step<8; ++step) // type
{
unsigned long dl = 0;
while(1)
{
for (idx = -1; idx<8-1; ) // row
{
SetRow(idx,range2[step][idx],false);
++idx;
SetRow(idx,range2[step][idx],true);
delay(1);
}
SetRow(idx,range2[step][idx],false);
}
//Clear();
}
}
}