Thông báo

Collapse
No announcement yet.

Đồng Hồ Số test không có lỗi những không chạy.

Collapse
X
 
  • Lọc
  • Giờ
  • Show
Clear All
new posts

  • Đồng Hồ Số test không có lỗi những không chạy.

    em làm cái đồng hồ số dùng 6 con 74hc595 hiển thị 6 led 7 thanh. nhưng không hiểu sao em dùng đồng hồ đo kiểm tra thông mạch. không còn chỗ nào lỗi. vậy mà cấp nguồn vào nó không chạy mà nó sáng hết các led.có bác nào gặp phải trường hợp này chưa. tư vấn giúp em với


  • #2
    Nguyên văn bởi hieuyeubich Xem bài viết
    em làm cái đồng hồ số dùng 6 con 74hc595 hiển thị 6 led 7 thanh. nhưng không hiểu sao em dùng đồng hồ đo kiểm tra thông mạch. không còn chỗ nào lỗi. vậy mà cấp nguồn vào nó không chạy mà nó sáng hết các led.có bác nào gặp phải trường hợp này chưa. tư vấn giúp em với
    up sơ đồ lên xem

    Comment


    • #3
      File mo phong..DSN
      đây là file mô phỏng

      Comment


      • #4
        nạp code đơn giản vào chip cho tạo xung chu kì vài giây rồi đo xem VDK có chạy hay ko

        Comment


        • #5
          Cái này của ong Le Duc He đấy mà.

          Nguyên văn bởi hieuyeubich Xem bài viết
          em làm cái đồng hồ số dùng 6 con 74hc595 hiển thị 6 led 7 thanh. nhưng không hiểu sao em dùng đồng hồ đo kiểm tra thông mạch. không còn chỗ nào lỗi. vậy mà cấp nguồn vào nó không chạy mà nó sáng hết các led.có bác nào gặp phải trường hợp này chưa. tư vấn giúp em với
          Tôi cũng làm cái này rồi nè, phần cứng bảo đảm đúng 100% nhưng cũng không chạy. hình như phải sủa code ở đâu đó không rõ vì code đó lấy giờ trên máy tính để mô phỏng vậy nên khi nạp file hex vào mạch rồi thì mạch không biết lấy giờ ở đâu mà chạy. tôi nghĩ vậy không biết có đúng không nữa, xin các bạn và các anh có kinh nghiệm chỉ giúp.
          code của nó đây:

          #include<reg52.h>
          sbit DATA1 = P3^0;
          sbit SCK1 = P3^1;
          sbit LACH1 = P3^2;
          sbit set=P3^4;
          sbit up=P3^5;
          sbit down=P3^6;
          unsigned char hour, minute, second,c;
          unsigned char ma[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x9 0};
          unsigned char kt=0,a=0,i,k,x=0;
          bit set0=1,set1=1,up1=1,up0=1,down0=1,down1=1;
          sbit SCL = P1^0;
          sbit SDA = P1^1;
          void delay(){
          unsigned char i;
          for (i = 0; i < 4; i++){};
          }

          //-----------------------------------------
          void SCL_high(){
          SCL = 1;
          delay();
          }

          //------------------------------------------
          void SCL_low(){
          SCL = 0;
          delay();
          }

          //-------------------------------------------
          void I2C_Start(){
          SDA = 1;
          SCL = 1;
          SDA = 0;
          delay();
          SCL = 0;
          SDA = 1;
          }

          //--------------------------------------------
          void I2C_Stop(){
          SDA = 0;
          SCL_high();
          SDA = 1;
          }

          //----------------------------------------------
          bit I2C_Write(unsigned char dat){
          unsigned char i;
          bit outbit;
          for (i = 1; i <= 8; i++){
          outbit=dat&0x80;
          SDA = outbit;
          dat = dat << 1;
          SCL_high();
          SCL_low();
          }
          SDA = 1;
          SCL_high();
          outbit = SDA;
          SCL_low();
          return(outbit);
          }

          //----------------------------------------------------
          unsigned char I2C_Read(bit ack){
          unsigned char i, dat;
          bit inbit;

          dat = 0;
          for(i=1;i<=8;i++) {
          SCL_high();
          inbit = SDA;
          dat = dat << 1;
          dat = dat | inbit;
          SCL_low();
          }
          if (ack) SDA = 0;
          else SDA = 1;
          SCL_high();
          SCL = 0;
          SDA = 1;
          delay();
          return(dat);
          }

          //-------------------------------------------------------------
          void rtc_write(unsigned char add, unsigned char dat){
          I2C_Start();
          I2C_Write(0xd0);
          I2C_Write(add);
          I2C_Write(((dat/10)<<4)|(dat%10));
          I2C_Stop();
          }

          unsigned char rtc_read(unsigned char add){
          unsigned char dat;
          I2C_Start();
          I2C_Write(0xd0);
          I2C_Write(add);
          I2C_Start();
          I2C_Write(0xd1);
          dat = I2C_Read(0);
          I2C_Stop();
          dat = (dat & 0x0f) + (dat>>4)*10;
          return (dat);
          }
          void writeds(){
          rtc_write(0x00, second);
          rtc_write(0x01, minute);
          rtc_write(0x02, hour);
          }

          void readds()
          {
          if(kt==0)
          {
          if(a==1)
          {writeds();a=0;
          }
          second = rtc_read(0x00);
          minute = rtc_read(0x01);
          hour = rtc_read(0x02);
          }
          }

          void hienthi(unsigned char x)
          {
          unsigned int i,temp;
          for(i=0;i<8;i++)
          {
          temp=x;
          temp=temp&0x80;
          if(temp==0x80)
          DATA1=1;
          else
          DATA1=0;
          x*=2;
          SCK1=0;
          SCK1=1;
          }
          }
          void quetled()
          {

          if(kt==0)
          {
          hienthi(ma[second%10]);
          hienthi(ma[second/10]);
          hienthi(ma[minute%10]);
          hienthi(ma[minute/10]);
          hienthi(ma[hour%10]);
          hienthi(ma[hour/10]);
          LACH1=0;
          LACH1=1;
          }
          if(kt==1)
          {
          hienthi(0xff);
          hienthi(0xff);
          hienthi(0xff);
          hienthi(0xff);
          hienthi(ma[hour%10]);
          hienthi(ma[hour/10]);
          LACH1=0;
          LACH1=1;
          }
          if(kt==2)
          {
          hienthi(0xff);
          hienthi(0xff);
          hienthi(ma[minute%10]);
          hienthi(ma[minute/10]);
          hienthi(0xff);
          hienthi(0xff);
          LACH1=0;
          LACH1=1;
          }
          if(kt==3)
          {
          hienthi(ma[second%10]);
          hienthi(ma[second/10]);
          hienthi(0xff);
          hienthi(0xff);
          hienthi(0xff);
          hienthi(0xff);
          LACH1=0;
          LACH1=1;
          }
          }
          void ktphim()
          {
          set0=set1;set1=set;
          if((set0==1)&&(set1==0))
          {
          kt++;
          if(kt>3)kt=0;
          }
          switch(kt)
          {
          case 0:break;
          case 1:
          {
          up0=up1;up1=up; a=1;
          if((up0==1)&&(up1==0))
          {
          hour++;
          if(hour>23)hour=0;
          }
          down0=down1;down1=down;
          if((down0==1)&&(down1==0))
          {
          hour--;
          if(hour==-1)
          hour=23;
          }
          break;
          }
          case 2:
          {
          up0=up1;up1=up; a=1;
          if((up0==1)&&(up1==0))
          {
          minute++;
          if(minute>59)
          minute=0;
          }
          down0=down1;down1=down;
          if((down0==1)&&(down1==0))
          {
          minute--;
          if(minute==-1)
          minute=59;
          }
          break;
          }

          case 3:
          {
          up0=up1;up1=up;a=1;
          if((up0==1)&&(up1==0))
          {
          second++;
          if(second>59)
          second++;
          }
          down0=down1;down1=down;
          if((down0==1)&&(down1==0))
          {
          second=0;
          }
          break;
          }
          }
          }

          void main()
          {
          I2C_Start();
          I2C_Write(0xD0);
          I2C_Write(0x07);
          I2C_Write(0x10);
          I2C_Stop();
          while(1)
          {
          ktphim();
          readds();
          quetled();
          }
          }

          bác nào rành mấy cái lập trình C này xin sửa giúp ạ.
          xin cám ơn trước

          Comment


          • #6
            lấy giờ của con DS1307 chứ đâu.

            Comment


            • #7
              Kiểm tra lại chỗ giao tiếp I2C giữa 89 và 1307 . nếu phần mạch đã ok rồi khi cấp nguồn vào mà sáng hết các số hoặc số sáng số ko , xung giây ko đếm là lỗi ở chỗ giao tiếp 2 ic , kiểm tra lại chỗ chân 7 của 1307 có xung 1HZ ra ko ? Mô phỏng ok thì làm mạch thật ok thôi . mô phỏng và thực tế chỉ khác đôi chút mà thôi .
              ................. Pleiku .................... GIA LAI ...................

              Comment


              • #8
                Nguyên văn bởi thi tran Xem bài viết
                Kiểm tra lại chỗ giao tiếp I2C giữa 89 và 1307 . nếu phần mạch đã ok rồi khi cấp nguồn vào mà sáng hết các số hoặc số sáng số ko , xung giây ko đếm là lỗi ở chỗ giao tiếp 2 ic , kiểm tra lại chỗ chân 7 của 1307 có xung 1HZ ra ko ? Mô phỏng ok thì làm mạch thật ok thôi . mô phỏng và thực tế chỉ khác đôi chút mà thôi .
                xung đo bằng đồng hồ có được ko bạn.của mình nó không chạy khi nó hiển thị lên phần giây nó hiện luôn là 80 và không chạy gì hết,nhưng vẫn có thể thay đổi được các số.mình đang nghi nó chết thạch anh ở ds1307 nhưng thay đến 4 con rồi cũng không chạy.mình thấy nó vẫn lưu được giờ khi rút điện ra nhưng mỗi tội không nhảy giây thôi chắc con 1307 nó vẫn chạy nhưng ko biết làm sao mà không nhảy giây.bạn có thể giúp mình chứ.bạn có thể nói cụ thể về cách đo xung ở chân 7 được không
                đùa chứ tớ hơi ngu...thông cảm nha..heee...

                Comment


                • #9
                  cái này bạn reset thanh ghi giây về 00h là chạy hoặc chỉ xóa bít cuối cùng của thanh ghi giây trên ds1307. lỗi này mọi người thường hay gặp phải mà.

                  Comment


                  • #10
                    [IMG][/IMG]Click image for larger version

Name:	3-16-2012 12-50-25 AM.jpg
Views:	1
Size:	72.9 KB
ID:	1358701Click image for larger version

Name:	3-16-2012 12-51-24 AM.png
Views:	1
Size:	85.7 KB
ID:	1358702
                    Nguyên văn bởi lengo90 Xem bài viết
                    cái này bạn reset thanh ghi giây về 00h là chạy hoặc chỉ xóa bít cuối cùng của thanh ghi giây trên ds1307. lỗi này mọi người thường hay gặp phải mà.
                    nhờ bác giúp em sửa luôn với,em làm mãi không dc mà nói đúng hơn chẳng biết sửa chỗ nào,vì chương trình này e cũng chỉ tham khảo thôi mà.cám ơn bác trước nhé!!
                    org 000h
                    jmp main
                    scl bit p1.0
                    sda bit p1.1
                    mode bit p3.0
                    tang bit p3.1
                    giam bit p3.2
                    hengio bit p3.4
                    giay bit 28h.0
                    phut bit 28h.1
                    gio bit 28h.2
                    ngay bit 28h.3
                    thang bit 28h.4
                    nam bit 28h.5
                    kiemtra bit 29h.0
                    tt bit 29h.1
                    diachi equ 30h
                    dulieu equ 32h
                    dulieund equ 33h
                    dulieunc equ 34h
                    dulieutd equ 35h
                    dulieutc equ 36h
                    dems equ 40h
                    demp equ 41h
                    demh equ 42h
                    demn equ 43h
                    demt equ 44h
                    demnd equ 45h
                    tam2 equ 49h
                    demndd equ 55h
                    demndc equ 56h
                    demncd equ 57h
                    demncc equ 58h
                    demp1 equ 59h
                    demh1 equ 60h
                    demp1d equ 61h
                    demp1c equ 62h
                    demh1d equ 63h
                    demh1c equ 64h
                    dem equ 65h
                    org 030h
                    ;################################################# ###############
                    ;############## Chuong trinh chinh ##########################
                    ;################################################# ###############
                    main:
                    clr p3.5
                    mov p0,#00h
                    mov dptr,#led7anode
                    mov dems,#00
                    mov demp,#00
                    mov demh,#00
                    mov demnd,#11
                    mov demn,#00
                    mov demt,#00
                    mov demh1,#00
                    mov demp1,#00
                    ;################################################# ################
                    ;############# Hien thi led 7 doan ##########################
                    ;################################################# ################
                    call nhanthoigian
                    clr p3.5
                    clr tt
                    clr kiemtra
                    hienthiled7doan:
                    call nhanthoigian
                    call quetled7doan
                    baothuc:
                    jnb kiemtra,kiemtramode
                    setb p3.5
                    jb mode,kiemtramode
                    call t50ms
                    jnb mode,$
                    clr p3.5
                    clr tt
                    clr kiemtra
                    jmp hienthiled7doan
                    kiemtramode:
                    jb mode,x
                    call t50ms
                    jnb mode,$
                    jmp chinhthoigian
                    x:
                    jb hengio,kiemtra1
                    call t50ms
                    jnb hengio,$
                    jmp hengio1
                    ;################################################# ################
                    ;################################################# ################
                    ;############# Bao thuc ##############################
                    ;################################################# ################
                    kiemtra1:
                    jnb tt,hienthiled7doan
                    mov a,r5
                    cjne a,demh1c,hienthiled7doan
                    call nhanthoigian
                    call quetled7doan
                    mov a,r4
                    cjne a,demh1d,hienthiled7doan
                    call nhanthoigian
                    call quetled7doan
                    mov a,r3
                    cjne a,demp1c,hienthiled7doan
                    call nhanthoigian
                    call quetled7doan
                    mov a,r2
                    cjne a,demp1d,hienthiled7doan
                    call nhanthoigian
                    call quetled7doan
                    setb kiemtra
                    jmp hienthiled7doan
                    ;################################################# ################
                    ;################################################# ################
                    ;############# Hen gio ##############################
                    ;################################################# ################
                    hengio1:
                    modeh1:
                    mov tam2,demh1
                    call chuyensangbcd
                    mov a,53h
                    movc a,@a+dptr
                    mov p2,a
                    setb p0.4
                    call t50ms
                    clr p0.4
                    mov a,52h
                    movc a,@a+dptr
                    mov p2,a
                    setb p0.5
                    call t50ms
                    clr p0.5
                    kiemtratangh1:
                    jb tang,kiemtragiamh1
                    call t50ms
                    jnb tang,$
                    inc demh1
                    mov a,demh1
                    cjne a,#24,modeh1
                    mov demh1,#00
                    jmp modeh1
                    kiemtragiamh1:
                    jb giam,kiemtramodep1
                    call t50ms
                    jnb giam,$
                    dec demh1
                    mov a,demh1
                    cjne a,#0ffh,modeh1
                    mov demh1,#23
                    jmp modeh1
                    kiemtramodep1:
                    jb hengio,modeh1
                    call t50ms
                    jnb hengio,$
                    modep1:
                    mov tam2,demh1
                    call chuyensangbcd
                    mov a,53h
                    movc a,@a+dptr
                    mov p2,a
                    setb p0.4
                    call t50ms
                    clr p0.4
                    mov a,52h
                    movc a,@a+dptr
                    mov p2,a
                    setb p0.5
                    call t50ms
                    clr p0.5
                    mov tam2,demp1
                    call chuyensangbcd
                    mov a,53h
                    movc a,@a+dptr
                    mov p2,a
                    setb p0.2
                    call t50ms
                    clr p0.2
                    mov a,52h
                    movc a,@a+dptr
                    mov p2,a
                    setb p0.3
                    call t50ms
                    clr p0.3
                    kiemtratangp1:
                    jb tang,kiemtragiamp1
                    call t50ms
                    jnb tang,$
                    inc demp1
                    mov a,demp1
                    cjne a,#60,modep1
                    mov demp1,#00
                    jmp modep1
                    kiemtragiamp1:
                    jb giam,kiemtramodes1
                    call t50ms
                    jnb giam,$
                    dec demp1
                    mov a,demp1
                    cjne a,#0ffh,modep1
                    mov demp1,#59
                    jmp modep1
                    kiemtramodes1:
                    jb hengio,modep1
                    call t50ms
                    jnb hengio,$
                    mov tam2,demp1
                    call chuyensangbcd
                    mov r1,#52h
                    mov r0,#53h
                    xchd a,@r1
                    swap a
                    xchd a,@r0
                    mov dulieu,a
                    mov diachi,#0ah
                    call truyen
                    mov tam2,demh1
                    call chuyensangbcd
                    mov r1,#52h
                    mov r0,#53h
                    xchd a,@r1
                    swap a
                    xchd a,@r0
                    mov dulieu,a
                    mov diachi,#0bh
                    call truyen
                    setb tt
                    jmp hienthiled7doan
                    ;################################################# ################
                    ;################################################# ################
                    ;############# Chinh thoi gian ##############################
                    ;################################################# ################
                    chinhthoigian:
                    mov 28h,#00
                    mov diachi,#00h
                    call nhan
                    mov tam2,dulieu
                    call chuyenbcdsanghex
                    mov dems,tam2
                    mov diachi,#01h
                    call nhan
                    mov tam2,dulieu
                    call chuyenbcdsanghex
                    mov demp,tam2
                    mov diachi,#02h
                    call nhan
                    mov tam2,dulieu
                    call chuyenbcdsanghex
                    mov demh,tam2
                    mov diachi,#04h
                    call nhan
                    mov tam2,dulieu
                    call chuyenbcdsanghex
                    mov demn,tam2
                    mov diachi,#05h
                    call nhan
                    mov tam2,dulieu
                    call chuyenbcdsanghex
                    mov demt,tam2
                    mov diachi,#06h
                    call nhan
                    mov tam2,dulieu
                    call chuyenbcdsanghex
                    mov demnd,tam2
                    mov dem,#020
                    modeh:
                    call quetled7doanchoptat
                    dec dem
                    mov a,dem
                    cjne a,#00,kiemtratangh
                    mov dem,#020
                    cpl gio
                    kiemtratangh:
                    jb tang,kiemtragiamh
                    call t50ms
                    jnb tang,$
                    inc demh
                    mov a,demh
                    cjne a,#24,modeh
                    mov demh,#00
                    jmp modeh
                    kiemtragiamh:
                    jb giam,kiemtramodep
                    call t50ms
                    jnb giam,$
                    dec demh
                    mov a,demh
                    cjne a,#0ffh,modeh
                    mov demh,#23
                    jmp modeh
                    kiemtramodep:
                    jb mode,modeh
                    call t50ms
                    jnb mode,$
                    mov 28h,#00
                    modep:
                    call quetled7doanchoptat
                    dec dem
                    mov a,dem
                    cjne a,#00,kiemtratangp
                    mov dem,#020
                    cpl phut
                    kiemtratangp:
                    jb tang,kiemtragiamp
                    call t50ms
                    jnb tang,$
                    inc demp
                    mov a,demp
                    cjne a,#60,modep
                    mov demp,#00
                    jmp modep
                    kiemtragiamp:
                    jb giam,kiemtramodes
                    call t50ms
                    jnb giam,$
                    dec demp
                    mov a,demp
                    cjne a,#0ffh,modep
                    mov demp,#59
                    jmp modep
                    kiemtramodes:
                    jb mode,modep
                    call t50ms
                    jnb mode,$
                    mov 28h,#00
                    modes:
                    call quetled7doanchoptat
                    dec dem
                    mov a,dem
                    cjne a,#00,kiemtratangs
                    mov dem,#020
                    cpl giay
                    kiemtratangs:
                    jb tang,kiemtragiams
                    call t50ms
                    jnb tang,$
                    inc dems
                    mov a,dems
                    cjne a,#60,modes
                    mov dems,#00
                    jmp modes
                    kiemtragiams:
                    jb giam,kiemtramoden
                    call t50ms
                    jnb giam,$
                    dec dems
                    mov a,dems
                    cjne a,#0ffh,modes
                    mov dems,#59
                    jmp modes
                    kiemtramoden:
                    jb mode,modes
                    call t50ms
                    jnb mode,$
                    mov 28h,#00
                    moden:
                    call quetled7doanchoptat
                    dec dem
                    mov a,dem
                    cjne a,#00,kiemtratangn
                    mov dem,#020
                    cpl ngay
                    kiemtratangn:
                    jb tang,kiemtragiamn
                    call t50ms
                    jnb tang,$
                    inc demn
                    mov a,demn
                    cjne a,#32,moden
                    mov demn,#00
                    jmp moden
                    kiemtragiamn:
                    jb giam,kiemtramodet
                    call t50ms
                    jnb giam,$
                    dec demn
                    mov a,demn
                    cjne a,#0ffh,moden
                    mov demn,#31
                    jmp moden
                    kiemtramodet:
                    jb mode,moden
                    call t50ms
                    jnb mode,$
                    mov 28h,#00
                    modet:
                    call quetled7doanchoptat
                    dec dem
                    mov a,dem
                    cjne a,#00,kiemtratangt
                    mov dem,#020
                    cpl thang
                    kiemtratangt:
                    jb tang,kiemtragiamt
                    call t50ms
                    jnb tang,$
                    inc demt
                    mov a,demt
                    cjne a,#13,modet
                    mov demt,#01
                    jmp modet
                    kiemtragiamt:
                    jb giam,kiemtramodenam
                    call t50ms
                    jnb giam,$
                    dec demt
                    mov a,demt
                    cjne a,#0ffh,modet
                    mov demt,#12
                    jmp modet
                    kiemtramodenam:
                    jb mode,modet
                    call t50ms
                    jnb mode,$
                    mov 28h,#00
                    modenam:
                    call quetled7doanchoptat
                    dec dem
                    mov a,dem
                    cjne a,#00,kiemtratangnam
                    mov dem,#020
                    cpl nam
                    kiemtratangnam:
                    jb tang,kiemtragiamnam
                    call t50ms
                    jnb tang,$
                    inc demnd
                    mov a,demnd
                    cjne a,#100,modenam
                    mov demnd,#00
                    jmp modenam
                    kiemtragiamnam:
                    jb giam,kiemtramodethoat
                    call t50ms
                    jnb giam,$
                    dec demnd
                    mov a,demnd
                    cjne a,#0ffh,modenam
                    mov demnd,#099
                    jmp modenam
                    kiemtramodethoat:
                    jb mode,modenam
                    call t50ms
                    jnb mode,$
                    call guithoigian
                    jmp hienthiled7doan
                    ;################################################# ################
                    ;################################################# ################
                    ;############# Nhan thoi gian ##############################
                    ;################################################# ################
                    nhanthoigian:
                    mov diachi,#00h
                    call nhan
                    mov tam2,dulieu
                    call chuyensanghex
                    mov r0,53h
                    mov r1,52h
                    mov diachi,#01h
                    call nhan
                    mov tam2,dulieu
                    call chuyensanghex
                    mov r2,53h
                    mov r3,52h
                    mov diachi,#02h
                    call nhan
                    mov tam2,dulieu
                    call chuyensanghex
                    mov r4,53h
                    mov r5,52h
                    mov diachi,#04h
                    call nhan
                    mov tam2,dulieu
                    call chuyensanghex
                    mov dulieund,53h
                    mov dulieunc,52h
                    mov diachi,#05h
                    call nhan
                    mov tam2,dulieu
                    call chuyensanghex
                    mov dulieutd,53h
                    mov dulieutc,52h
                    mov diachi,#06h
                    call nhan
                    mov tam2,dulieu
                    call chuyensanghex
                    mov demndd,53h
                    mov demndc,52h
                    jnb tt,x2
                    mov diachi,#0ah
                    call nhan
                    mov tam2,dulieu
                    call chuyensanghex
                    mov demp1d,53h
                    mov demp1c,52h
                    mov diachi,#0bh
                    call nhan
                    mov tam2,dulieu
                    call chuyensanghex
                    mov demh1d,53h
                    mov demh1c,52h
                    x2:
                    ret
                    ;################################################# ################
                    ;################################################# ################
                    ;############# Gui thoi gian ###############################
                    ;################################################# ################
                    guithoigian:
                    mov tam2,dems
                    call chuyensangbcd
                    mov r1,#52h
                    mov r0,#53h
                    xchd a,@r1
                    swap a
                    xchd a,@r0
                    mov dulieu,a
                    mov diachi,#00h
                    call truyen
                    mov tam2,demp
                    call chuyensangbcd
                    mov r1,#52h
                    mov r0,#53h
                    xchd a,@r1
                    swap a
                    xchd a,@r0
                    mov dulieu,a
                    mov diachi,#01h
                    call truyen
                    mov tam2,demh
                    call chuyensangbcd
                    mov r1,#52h
                    mov r0,#53h
                    xchd a,@r1
                    swap a
                    xchd a,@r0
                    mov dulieu,a
                    mov diachi,#02h
                    call truyen
                    mov tam2,demn
                    call chuyensangbcd
                    mov r1,#52h
                    mov r0,#53h
                    xchd a,@r1
                    swap a
                    xchd a,@r0
                    mov dulieu,a
                    mov diachi,#04h
                    call truyen
                    mov tam2,demt
                    call chuyensangbcd
                    mov r1,#52h
                    mov r0,#53h
                    xchd a,@r1
                    swap a
                    xchd a,@r0
                    mov dulieu,a
                    mov diachi,#05h
                    call truyen
                    mov tam2,demnd
                    call chuyensangbcd
                    mov r1,#52h
                    mov r0,#53h
                    xchd a,@r1
                    swap a
                    xchd a,@r0
                    mov dulieu,a
                    mov diachi,#06h
                    call truyen
                    ret
                    ;################################################# ################
                    ;################################################# ################
                    ;############# Truyen I2C ###################################
                    ;################################################# ################
                    ;################################################# ################
                    ;################################################# ################
                    ;############# Nhan du lieu #################################
                    ;################################################# ################
                    nhan:
                    call start
                    mov a,#0d0h
                    call send
                    setb sda
                    setb scl
                    jb sda,nhan
                    clr scl
                    mov a,diachi
                    call send
                    setb sda
                    setb scl
                    jb sda,nhan
                    clr scl
                    call start
                    mov a,#0d1h
                    call send
                    setb sda
                    setb scl
                    jb sda,nhan
                    clr scl
                    call receive
                    call stop
                    ret
                    receive:
                    mov r7,#08h
                    lap_receive:
                    setb scl
                    mov c,sda
                    clr scl
                    rlc a
                    djnz r7,lap_receive
                    mov dulieu,a
                    setb scl
                    clr sda
                    clr scl
                    ret
                    ;################################################# ################
                    ;################################################# ################
                    ;############# Truyen du lieu ###############################
                    ;################################################# ################
                    truyen:
                    call start
                    mov a,#0d0h
                    call send
                    setb sda
                    setb scl
                    jb sda,truyen
                    clr scl
                    mov a,diachi
                    call send
                    setb sda
                    setb scl
                    jb sda,truyen
                    clr scl
                    mov a,dulieu
                    call send
                    setb sda
                    setb scl
                    jb sda,truyen
                    clr scl
                    call stop
                    ret
                    send:
                    mov r7,#08h
                    lap_send:
                    rlc a
                    mov sda,c
                    setb scl
                    clr scl
                    djnz r7,lap_send
                    ret
                    ;################################################# ################
                    ;################################################# ################
                    ;############# Start I2C ####################################
                    ;################################################# ################
                    start:
                    setb sda
                    setb scl
                    nop
                    nop
                    clr sda
                    nop
                    nop
                    clr scl
                    nop
                    ret
                    ;################################################# ################
                    ;################################################# ################
                    ;############# Stop I2C #####################################
                    ;################################################# ################
                    stop:
                    clr sda
                    nop
                    nop
                    setb scl
                    nop
                    nop
                    setb sda
                    ret
                    ;################################################# ################
                    ;################################################# ################
                    ;############# Quet led 7 doan chop tat #####################
                    ;################################################# ################
                    quetled7doanchoptat:
                    jb gio,phut1
                    mov tam2,demh
                    call chuyensangbcd
                    mov a,53h
                    movc a,@a+dptr
                    mov p2,a
                    setb p0.4
                    call t50ms
                    clr p0.4
                    mov a,52h
                    movc a,@a+dptr
                    mov p2,a
                    setb p0.5
                    call t50ms
                    clr p0.5
                    phut1:
                    jb phut,giay1
                    mov tam2,demp
                    call chuyensangbcd
                    mov a,53h
                    movc a,@a+dptr
                    mov p2,a
                    setb p0.2
                    call t50ms
                    clr p0.2
                    mov a,52h
                    movc a,@a+dptr
                    mov p2,a
                    setb p0.3
                    call t50ms
                    clr p0.3
                    giay1:
                    jb giay,ngay1
                    mov tam2,dems
                    call chuyensangbcd
                    mov a,53h
                    movc a,@a+dptr
                    mov p2,a
                    setb p0.0
                    call t50ms
                    clr p0.0
                    mov a,52h
                    movc a,@a+dptr
                    mov p2,a
                    setb p0.1
                    call t50ms
                    clr p0.1
                    ngay1:
                    jb ngay,thang1
                    mov tam2,demn
                    call chuyensangbcd
                    mov a,53h
                    movc a,@a+dptr
                    mov p2,a
                    setb p0.7
                    call t50ms
                    clr p0.7
                    mov a,52h
                    movc a,@a+dptr
                    mov p2,a
                    setb p0.6
                    call t50ms
                    clr p0.6
                    thang1:
                    jb thang,nam1
                    mov tam2,demt
                    call chuyensangbcd
                    mov a,53h
                    movc a,@a+dptr
                    mov p2,a
                    setb p1.3
                    call t50ms
                    clr p1.3
                    mov a,52h
                    movc a,@a+dptr
                    mov p2,a
                    setb p1.2
                    call t50ms
                    clr p1.2
                    nam1:
                    jb nam,thoatquet
                    mov tam2,demnd
                    call chuyensangbcd
                    mov a,53h
                    movc a,@a+dptr
                    mov p2,a
                    setb p1.7
                    call t50ms
                    clr p1.7
                    mov a,52h
                    movc a,@a+dptr
                    mov p2,a
                    setb p1.6
                    call t50ms
                    clr p1.6
                    mov a,#00h
                    movc a,@a+dptr
                    mov p2,a
                    setb p1.5
                    call t50ms
                    clr p1.5
                    mov a,#02h
                    movc a,@a+dptr
                    mov p2,a
                    setb p1.4
                    call t50ms
                    clr p1.4
                    ret
                    thoatquet:
                    ret
                    ;################################################# ################
                    ;################################################# ################
                    ;############# Quet led 7 doan ##############################
                    ;################################################# ################
                    quetled7doan:
                    mov a,r0
                    movc a,@a+dptr
                    mov p2,a
                    setb p0.0
                    call t50ms
                    clr p0.0
                    mov a,r1
                    movc a,@a+dptr
                    mov p2,a
                    setb p0.1
                    call t50ms
                    clr p0.1
                    mov a,r2
                    movc a,@a+dptr
                    mov p2,a
                    setb p0.2
                    call t50ms
                    clr p0.2
                    mov a,r3
                    movc a,@a+dptr
                    mov p2,a
                    setb p0.3
                    call t50ms
                    clr p0.3
                    mov a,r4
                    movc a,@a+dptr
                    mov p2,a
                    setb p0.4
                    call t50ms
                    clr p0.4
                    mov a,r5
                    movc a,@a+dptr
                    mov p2,a
                    setb p0.5
                    call t50ms
                    clr p0.5
                    mov a,dulieund
                    movc a,@a+dptr
                    mov p2,a
                    setb p0.7
                    call t50ms
                    clr p0.7
                    mov a,dulieunc
                    movc a,@a+dptr
                    mov p2,a
                    setb p0.6
                    call t50ms
                    clr p0.6
                    mov a,dulieutd
                    movc a,@a+dptr
                    mov p2,a
                    setb p1.3
                    call t50ms
                    clr p1.3
                    mov a,dulieutc
                    movc a,@a+dptr
                    mov p2,a
                    setb p1.2
                    call t50ms
                    clr p1.2
                    mov a,demndd
                    movc a,@a+dptr
                    mov p2,a
                    setb p1.7
                    call t50ms
                    clr p1.7
                    mov a,demndc
                    movc a,@a+dptr
                    mov p2,a
                    setb p1.6
                    call t50ms
                    clr p1.6
                    mov a,#00h
                    movc a,@a+dptr
                    mov p2,a
                    setb p1.5
                    call t50ms
                    clr p1.5
                    mov a,#02h
                    movc a,@a+dptr
                    mov p2,a
                    setb p1.4
                    call t50ms
                    clr p1.4
                    ret
                    ;################################################# #######################
                    ;################################################# #######################
                    ;############################# Thoi gian quet led #######################
                    ;################################################# #######################
                    t50ms:
                    push 30h
                    push 31h
                    mov 30h,#4
                    mov 31h,#1
                    lap:
                    djnz 31h,$
                    djnz 30h,lap
                    pop 31h
                    pop 30h
                    ret
                    ;################################################# ########################
                    ;################################################# ########################
                    ;########################## Chuyen BCD sang HEX ##########################
                    ;################################################# ########################
                    chuyenbcdsanghex:
                    mov a,tam2
                    anl a,#00001111b
                    mov 53h,a
                    mov a,tam2
                    anl a,#11110000b
                    swap a
                    mov 52h,a
                    mov b,52h
                    mov a,#0ah
                    mul ab
                    add a,53h
                    mov tam2,a
                    ret
                    ;################################################# ########################
                    ;################################################# ########################
                    ;########################## Chuyen sang HEX ##############################
                    ;################################################# ########################
                    chuyensanghex:
                    mov a,tam2
                    anl a,#00001111b
                    mov 53h,a
                    mov a,tam2
                    anl a,#11110000b
                    swap a
                    mov 52h,a
                    ret
                    ;################################################# ########################
                    ;################################################# ########################
                    ;########################## Chuyen sang BCD ##############################
                    ;################################################# ########################
                    chuyensangbcd:
                    tam equ 51h
                    tam1 equ 50h
                    mov tam,tam2
                    mov a,tam
                    mov b,#10
                    div ab
                    mov 52h,a
                    mov b,#10
                    mul ab
                    mov tam1,a
                    mov a,tam
                    clr c
                    subb a,tam1
                    mov 53h,a
                    ret
                    ;################################################# ############################
                    ;################################################# ############################
                    ;###################### Du lieu quet led 7 doan ##############################
                    ;################################################# ############################
                    led7anode:
                    db 01000000b,01111001b,00100100b,00110000b,00011001b, 00010010b,00000010b,01111000b,00000000b,00010000b
                    ;################################################# ############################
                    end
                    Last edited by toan258; 16-03-2012, 02:06.
                    đùa chứ tớ hơi ngu...thông cảm nha..heee...

                    Comment


                    • #11
                      mình chỉ biết hướng dẫn vậy thôi chứ bảo mình đọc cả đoạn code dài thế kia mình nhìn thôi đã thấy hoa mắt rồi chứ không nói đến sửa giúp bạn. ai hảo tâm sửa giúp bạn ấy với, chỉ cần lưu giá trị 00h vào thanh ghi giây lần đầu để reset lại thôi rồi lần sau lại nạp code cũ là chạy

                      Comment


                      • #12
                        phải khởi tạo cho ds1307 trc ,để bit lớn nhất về 0 là chạy thôi.bạn lấy tạm đoạn code c này mà tham khảo nè
                        //******************************* ************************************************** *
                        unsigned char read_byteds1307(unsigned char addres)
                        {
                        unsigned char d;
                        startds1307();
                        write_datads1307(0xd0); // dau tien gui lenh ghi du lieu(ghi dia chi can lay du lieu trong DS1307)
                        write_datads1307(addres); // gui lenh doc gia tri tu dia chi can truy xuat
                        startds1307();
                        write_datads1307(0xd1); // gui ma lenh doc du lieu tu dia chi(add) da ghi o tren
                        d=read_datads1307(); //doc gia tri cua RTC ra
                        stopds1307();
                        return d; //tra du lieu
                        }
                        //******************************* ************************************************** *
                        void write_byteds1307(unsigned char addres,unsigned char d)
                        {
                        startds1307(); //khoi tao i2c
                        write_datads1307(0xd0);//dia chi ds1307 la 0xd0
                        write_datads1307(addres);//addres dia chi thanh ghi can ghi trong rtc
                        write_datads1307(d); //du lieu can ghi
                        stopds1307(); //dung i2c
                        }
                        void main()
                        s=read_byteds1307(0x0); // khoi tao ds1307
                        s=s&0x7f;
                        write_byteds1307(0x0,s);

                        Comment


                        • #13
                          hixx...để em ngu kứu vậy..nan giải nhỉ...
                          đùa chứ tớ hơi ngu...thông cảm nha..heee...

                          Comment


                          • #14
                            Code đồng hồ báo thức có chớp tắt 1s ở chân số 7 của con ds1307
                            org 000h
                            jmp main
                            scl bit p1.0
                            sda bit p1.1
                            mode bit p3.0 
                            tang bit p3.1
                            giam bit p3.2
                            hengio bit p3.4
                            giay bit 28h.0
                            phut bit 28h.1
                            gio bit 28h.2
                            ngay bit 28h.3
                            thang bit 28h.4
                            nam bit 28h.5
                            kiemtra bit 29h.0
                            tt bit 29h.1
                            diachi equ 30h
                            dulieu equ 32h
                            dulieund equ 33h
                            dulieunc equ 34h
                            dulieutd equ 35h
                            dulieutc equ 36h
                            dems equ 40h
                            demp equ 41h
                            demh equ 42h
                            demn equ 43h
                            demt equ 44h
                            demnd equ 45h
                            tam2 equ 49h
                            demndd equ 55h
                            demndc equ 56h
                            demncd equ 57h
                            demncc equ 58h
                            demp1 equ 59h
                            demh1 equ 60h
                            demp1d equ 61h
                            demp1c equ 62h
                            demh1d equ 63h
                            demh1c equ 64h
                            dem equ 65h
                            ADD_LOW EQU 66H
                            DATA_DS EQU 67H
                            BYTE_W EQU 11010000B
                            org 030h
                            ;##############     Chuong trinh chinh ##########################
                            main:
                            clr p3.5
                            mov p0,#00h
                            mov dptr,#led7anode
                            mov dems,#00
                            mov demp,#00
                            mov demh,#00
                            mov demnd,#11
                            mov demn,#00
                            mov demt,#00
                            mov demh1,#00
                            mov demp1,#00
                            MOV ADD_LOW,#7
                            MOV DATA_DS,#00010000b ;tao xung 1hz t?i chân (7)ds1307
                            LCALL WRITE_BYTE
                            ;############# Hien thi led 7 doan ##########################
                            Lcall nhanthoigian
                            clr p3.5
                            clr tt
                            clr kiemtra
                            hienthiled7doan: 
                            Lcall nhanthoigian
                            Lcall quetled7doan
                            baothuc:
                            jnb kiemtra,kiemtramode
                            setb p3.5
                            jb mode,kiemtramode
                            call t50ms
                            jnb mode,$
                            clr p3.5
                            clr tt
                            clr kiemtra
                            jmp hienthiled7doan
                            kiemtramode:
                            jb mode,x
                            call t50ms
                            jnb mode,$
                            jmp chinhthoigian
                            x:
                            jb hengio,kiemtra1
                            call t50ms
                            jnb hengio,$
                            jmp hengio1
                            ;############# Bao thuc     ##############################
                            kiemtra1:
                            jnb tt,hienthiled7doan
                            mov a,r5
                            cjne a,demh1c,hienthiled7doan
                            Lcall nhanthoigian
                            Lcall quetled7doan
                            mov a,r4
                            cjne a,demh1d,hienthiled7doan
                            Lcall nhanthoigian
                            Lcall quetled7doan
                            mov a,r3
                            cjne a,demp1c,hienthiled7doan
                            Lcall nhanthoigian
                            Lcall quetled7doan
                            mov a,r2
                            cjne a,demp1d,hienthiled7doan
                            Lcall nhanthoigian
                            Lcall quetled7doan
                            setb kiemtra
                            jmp hienthiled7doan
                            ;############# Hen gio  ##############################
                            hengio1:
                            modeh1:
                            mov tam2,demh1
                            call chuyensangbcd
                            mov a,53h
                            movc a,@a+dptr
                            mov p0,a
                            CLR p2.4
                            call t50ms
                            SETB p2.4
                            mov a,52h
                            movc a,@a+dptr
                            mov p0,a
                            CLR p2.5
                            call t50ms
                            SETB p2.5
                            kiemtratangh1:
                            jb tang,kiemtragiamh1
                            call t50ms
                            jnb tang,$
                            inc demh1
                            mov a,demh1
                            cjne a,#24,modeh1
                            mov demh1,#00
                            jmp modeh1
                            kiemtragiamh1:
                            jb giam,kiemtramodep1
                            call t50ms
                            jnb giam,$
                            dec demh1
                            mov a,demh1
                            cjne a,#0ffh,modeh1
                            mov demh1,#23
                            jmp modeh1
                            kiemtramodep1:
                            jb hengio,modeh1
                            call t50ms
                            jnb hengio,$
                            modep1:
                            mov tam2,demh1
                            call chuyensangbcd
                            mov a,53h
                            movc a,@a+dptr
                            mov p0,a
                            CLR p2.4
                            call t50ms
                            SETB p2.4
                            mov a,52h
                            movc a,@a+dptr
                            mov p0,a
                            CLR p2.5
                            call t50ms
                            SETB p2.5
                            mov tam2,demp1
                            call chuyensangbcd
                            mov a,53h
                            movc a,@a+dptr
                            mov p0,a
                            CLR p2.2
                            call t50ms
                            SETB p2.2
                            mov a,52h
                            movc a,@a+dptr
                            mov p0,a
                            CLR p2.3
                            call t50ms
                            SETB p2.3
                            kiemtratangp1:
                            jb tang,kiemtragiamp1
                            call t50ms
                            jnb tang,$
                            inc demp1
                            mov a,demp1
                            cjne a,#60,modep1
                            mov demp1,#00
                            jmp modep1
                            kiemtragiamp1:
                            jb giam,kiemtramodes1
                            call t50ms
                            jnb giam,$
                            dec demp1
                            mov a,demp1
                            cjne a,#0ffh,modep1
                            mov demp1,#59
                            jmp modep1
                            kiemtramodes1:
                            jb hengio,modep1
                            call t50ms
                            jnb hengio,$
                            mov tam2,demp1
                            call chuyensangbcd
                            mov r1,#52h
                            mov r0,#53h
                            xchd a,@r1
                            swap a
                            xchd a,@r0
                            mov dulieu,a
                            mov diachi,#0ah
                            call truyen
                            mov tam2,demh1
                            call chuyensangbcd
                            mov r1,#52h
                            mov r0,#53h
                            xchd a,@r1
                            swap a
                            xchd a,@r0
                            mov dulieu,a
                            mov diachi,#0bh
                            call truyen
                            setb tt
                            jmp hienthiled7doan
                            ;############# Chinh thoi gian     ##############################
                            chinhthoigian:
                            mov 28h,#00
                            mov diachi,#00h
                            call nhan
                            mov tam2,dulieu
                            call chuyenbcdsanghex
                            mov dems,tam2
                            mov diachi,#01h
                            call nhan
                            mov tam2,dulieu
                            call chuyenbcdsanghex
                            mov demp,tam2
                            mov diachi,#02h
                            call nhan
                            mov tam2,dulieu
                            call chuyenbcdsanghex
                            mov demh,tam2
                            mov diachi,#04h
                            call nhan
                            mov tam2,dulieu
                            call chuyenbcdsanghex
                            mov demn,tam2
                            mov diachi,#05h
                            call nhan
                            mov tam2,dulieu
                            call chuyenbcdsanghex
                            mov demt,tam2
                            mov diachi,#06h
                            call nhan
                            mov tam2,dulieu
                            call chuyenbcdsanghex
                            mov demnd,tam2
                            mov dem,#020
                            modeh:
                            Lcall quetled7doanchoptat
                            dec dem
                            mov a,dem
                            cjne a,#00,kiemtratangh
                            mov dem,#020
                            cpl gio
                            kiemtratangh:
                            jb tang,kiemtragiamh
                            call t50ms
                            jnb tang,$
                            inc demh
                            mov a,demh
                            cjne a,#24,modeh
                            mov demh,#00
                            jmp modeh
                            kiemtragiamh:
                            jb giam,kiemtramodep
                            call t50ms
                            jnb giam,$
                            dec demh
                            mov a,demh
                            cjne a,#0ffh,modeh
                            mov demh,#23
                            jmp modeh
                            kiemtramodep:
                            jb mode,modeh
                            call t50ms
                            jnb mode,$
                            mov 28h,#00
                            modep:
                            Lcall quetled7doanchoptat
                            dec dem
                            mov a,dem
                            cjne a,#00,kiemtratangp
                            mov dem,#020
                            cpl phut
                            kiemtratangp:
                            jb tang,kiemtragiamp
                            call t50ms
                            jnb tang,$
                            inc demp
                            mov a,demp
                            cjne a,#60,modep
                            mov demp,#00
                            jmp modep
                            kiemtragiamp:
                            jb giam,kiemtramodes
                            call t50ms
                            jnb giam,$
                            dec demp
                            mov a,demp
                            cjne a,#0ffh,modep
                            mov demp,#59
                            jmp modep
                            kiemtramodes:
                            jb mode,modep
                            call t50ms
                            jnb mode,$
                            mov 28h,#00
                            modes:
                            Lcall quetled7doanchoptat
                            dec dem
                            mov a,dem
                            cjne a,#00,kiemtratangs
                            mov dem,#020
                            cpl giay
                            kiemtratangs:
                            jb tang,kiemtragiams
                            call t50ms
                            jnb tang,$
                            inc dems
                            mov a,dems
                            cjne a,#60,modes
                            mov dems,#00
                            jmp modes
                            kiemtragiams:
                            jb giam,kiemtramoden
                            call t50ms
                            jnb giam,$
                            dec dems
                            mov a,dems
                            cjne a,#0ffh,modes
                            mov dems,#59
                            jmp modes
                            kiemtramoden:
                            jb mode,modes
                            call t50ms
                            jnb mode,$
                            mov 28h,#00
                            moden:
                            Lcall quetled7doanchoptat
                            dec dem
                            mov a,dem
                            cjne a,#00,kiemtratangn
                            mov dem,#020
                            cpl ngay
                            kiemtratangn:
                            jb tang,kiemtragiamn
                            call t50ms
                            jnb tang,$
                            inc demn
                            mov a,demn
                            cjne a,#32,moden
                            mov demn,#00
                            jmp moden
                            kiemtragiamn:
                            jb giam,kiemtramodet
                            call t50ms
                            jnb giam,$
                            dec demn
                            mov a,demn
                            cjne a,#0ffh,moden
                            mov demn,#31
                            jmp moden
                            kiemtramodet:
                            jb mode,moden
                            call t50ms
                            jnb mode,$
                            mov 28h,#00
                            modet:
                            Lcall quetled7doanchoptat
                            dec dem
                            mov a,dem
                            cjne a,#00,kiemtratangt
                            mov dem,#020
                            cpl thang
                            kiemtratangt:
                            jb tang,kiemtragiamt
                            call t50ms
                            jnb tang,$
                            inc demt
                            mov a,demt
                            cjne a,#13,modet
                            mov demt,#01
                            jmp modet
                            kiemtragiamt:
                            jb giam,kiemtramodenam
                            call t50ms
                            jnb giam,$
                            dec demt
                            mov a,demt
                            cjne a,#0ffh,modet
                            mov demt,#12
                            jmp modet
                            kiemtramodenam:
                            jb mode,modet
                            call t50ms
                            jnb mode,$
                            mov 28h,#00
                            modenam:
                            Lcall quetled7doanchoptat
                            dec dem
                            mov a,dem
                            cjne a,#00,kiemtratangnam
                            mov dem,#020
                            cpl nam
                            kiemtratangnam:
                            jb tang,kiemtragiamnam
                            call t50ms
                            jnb tang,$
                            inc demnd
                            mov a,demnd
                            cjne a,#100,modenam
                            mov demnd,#00
                            jmp modenam
                            kiemtragiamnam:
                            jb giam,kiemtramodethoat
                            call t50ms
                            jnb giam,$
                            dec demnd
                            mov a,demnd
                            cjne a,#0ffh,modenam
                            mov demnd,#099
                            jmp modenam
                            kiemtramodethoat:
                            jb mode,modenam
                            call t50ms
                            jnb mode,$
                            call guithoigian
                            jmp hienthiled7doan
                            ;############# Nhan  thoi gian ##############################
                            nhanthoigian:
                            mov diachi,#00h
                            call nhan
                            mov tam2,dulieu
                            call chuyensanghex
                            mov r0,53h
                            mov r1,52h
                            mov diachi,#01h
                            call nhan
                            mov tam2,dulieu
                            call chuyensanghex
                            mov r2,53h
                            mov r3,52h  
                            mov diachi,#02h
                            call nhan
                            mov tam2,dulieu
                            call chuyensanghex
                            mov r4,53h
                            mov r5,52h
                            mov diachi,#04h
                            call nhan
                            mov tam2,dulieu
                            call chuyensanghex
                            mov dulieund,53h
                            mov dulieunc,52h
                            mov diachi,#05h
                            call nhan
                            mov tam2,dulieu
                            call chuyensanghex
                            mov dulieutd,53h
                            mov dulieutc,52h
                            mov diachi,#06h
                            call nhan
                            mov tam2,dulieu
                            call chuyensanghex
                            mov demndd,53h
                            mov demndc,52h
                            jnb tt,x2
                            mov diachi,#0ah
                            call nhan
                            mov tam2,dulieu
                            call chuyensanghex
                            mov demp1d,53h
                            mov demp1c,52h
                            mov diachi,#0bh
                            call nhan
                            mov tam2,dulieu
                            call chuyensanghex
                            mov demh1d,53h
                            mov demh1c,52h
                            x2:
                            ret
                            ;############# Gui  thoi gian ###############################
                            guithoigian:
                            mov tam2,dems
                            call chuyensangbcd
                            mov r1,#52h
                            mov r0,#53h
                            xchd a,@r1
                            swap a
                            xchd a,@r0
                            mov dulieu,a
                            mov diachi,#00h
                            call truyen
                            mov tam2,demp
                            call chuyensangbcd
                            mov r1,#52h
                            mov r0,#53h
                            xchd a,@r1
                            swap a
                            xchd a,@r0
                            mov dulieu,a
                            mov diachi,#01h
                            call truyen
                            mov tam2,demh
                            call chuyensangbcd
                            mov r1,#52h
                            mov r0,#53h
                            xchd a,@r1
                            swap a
                            xchd a,@r0
                            mov dulieu,a
                            mov diachi,#02h
                            call truyen  
                            mov tam2,demn
                            call chuyensangbcd
                            mov r1,#52h
                            mov r0,#53h
                            xchd a,@r1
                            swap a
                            xchd a,@r0
                            mov dulieu,a
                            mov diachi,#04h
                            call truyen  
                            mov tam2,demt
                            call chuyensangbcd
                            mov r1,#52h
                            mov r0,#53h
                            xchd a,@r1
                            swap a
                            xchd a,@r0
                            mov dulieu,a
                            mov diachi,#05h
                            call truyen 
                            mov tam2,demnd
                            call chuyensangbcd
                            mov r1,#52h
                            mov r0,#53h
                            xchd a,@r1
                            swap a
                            xchd a,@r0
                            mov dulieu,a
                            mov diachi,#06h
                            call truyen 
                            ret
                            ;############# Truyen I2C ###################################
                            ;############# Nhan du lieu #################################
                            nhan:
                            call start
                            mov a,#0d0h
                            call send
                            setb sda
                            setb scl
                            jb sda,nhan
                            clr scl
                            mov a,diachi
                            call send
                            setb sda
                            setb scl
                            jb sda,nhan
                            clr scl
                            call start
                            mov a,#0d1h
                            call send
                            setb sda
                            setb scl
                            jb sda,nhan
                            clr scl
                            call receive
                            call stop
                            ret
                            receive:
                            mov r7,#08h
                            lap_receive:
                            setb scl
                            mov c,sda
                            clr scl
                            rlc a
                            djnz r7,lap_receive
                            mov dulieu,a
                            setb scl
                            clr sda
                            clr scl
                            ret
                            ;############# Truyen du lieu ###############################
                            truyen:
                            call start
                            mov a,#0d0h
                            call send
                            setb sda
                            setb scl
                            jb sda,truyen
                            clr scl
                            mov a,diachi
                            call send
                            setb sda
                            setb scl
                            jb sda,truyen
                            clr scl
                            mov a,dulieu
                            call send
                            setb sda
                            setb scl
                            jb sda,truyen
                            clr scl
                            call stop
                            ret
                            send:
                            mov r7,#08h
                            lap_send:
                            rlc a
                            mov sda,c
                            setb scl
                            clr scl
                            djnz r7,lap_send
                            ret




                            ;############# Start I2C ####################################
                            start:
                            setb sda
                            setb scl
                            nop
                            nop
                            clr sda
                            nop
                            nop
                            clr scl
                            nop
                            ret
                            ;#############Stop I2C #####################################
                            stop:
                            clr sda
                            nop
                            nop
                            setb scl
                            nop
                            nop
                            setb sda
                            ret
                            ;#############Quet led 7 doan chop tat #####################
                            quetled7doanchoptat:
                            jb gio,phut1
                            mov tam2,demh
                            call chuyensangbcd
                            mov a,53h
                            movc a,@a+dptr
                            mov p0,a
                            CLR p2.4
                            call t50ms
                            SETB p2.4
                            mov a,52h
                            movc a,@a+dptr
                            mov p0,a
                            CLR p2.5
                            call t50ms
                            SETB p2.5
                            phut1:
                            jb phut,giay1
                            mov tam2,demp
                            call chuyensangbcd
                            mov a,53h
                            movc a,@a+dptr
                            mov p0,a
                            CLR p2.2
                            call t50ms
                            SETB p2.2
                            mov a,52h
                            movc a,@a+dptr
                            mov p0,a
                            CLR p2.3
                            call t50ms
                            SETB p2.3
                            giay1:
                            jb giay,ngay1
                            mov tam2,dems
                            call chuyensangbcd
                            mov a,53h
                            movc a,@a+dptr
                            mov p0,a
                            CLR p2.0
                            call t50ms
                            SETB p2.0
                            mov a,52h
                            movc a,@a+dptr
                            mov p0,a
                            CLR p2.1
                            call t50ms
                            SETB p2.1
                            ngay1:
                            jb ngay,thang1
                            mov tam2,demn
                            call chuyensangbcd
                            mov a,53h
                            movc a,@a+dptr
                            mov p0,a
                            CLR p2.7
                            call t50ms
                            SETB p2.7
                            mov a,52h
                            movc a,@a+dptr
                            mov p0,a
                            CLR p2.6
                            call t50ms
                            SETB p2.6
                            thang1:
                            jb thang,nam1
                            mov tam2,demt
                            call chuyensangbcd
                            mov a,53h
                            movc a,@a+dptr
                            mov p0,a
                            CLR p1.3
                            call t50ms
                            SETB p1.3
                            mov a,52h
                            movc a,@a+dptr
                            mov p0,a
                            CLR p1.2
                            call t50ms
                            SETB p1.2
                            nam1:
                            jb nam,thoatquet
                            mov tam2,demnd
                            call chuyensangbcd
                            mov a,53h
                            movc a,@a+dptr
                            mov p0,a
                            CLR p1.7
                            call t50ms
                            SETB p1.7
                            mov a,52h
                            movc a,@a+dptr
                            mov p0,a
                            CLR p1.6
                            call t50ms
                            SETB p1.6
                            mov a,#00h
                            movc a,@a+dptr
                            mov p0,a
                            CLR p1.5
                            call t50ms
                            SETB p1.5
                            mov a,#02h
                            movc a,@a+dptr
                            mov p0,a
                            CLR p1.4
                            call t50ms
                            SETB p1.4
                            ret
                            thoatquet:
                            ret
                            ;#############Quet led 7 doan ##############################
                            quetled7doan:
                            mov a,r0
                            movc a,@a+dptr
                            mov p0,a
                            CLR p2.0
                            call t50ms
                            SETB p2.0
                            mov a,r1
                            movc a,@a+dptr
                            mov p0,a
                            CLR p2.1
                            call t50ms
                            SETB p2.1
                            mov a,r2
                            movc a,@a+dptr
                            mov p0,a
                            CLR p2.2
                            call t50ms
                            SETB p2.2
                            mov a,r3
                            movc a,@a+dptr
                            mov p0,a
                            CLR p2.3
                            call t50ms
                            SETB p2.3
                            mov a,r4
                            movc a,@a+dptr
                            mov p0,a
                            CLR p2.4
                            call t50ms
                            SETB p2.4
                            mov a,r5
                            movc a,@a+dptr
                            mov p0,a
                            CLR p2.5
                            call t50ms
                            SETB p2.5
                            mov a,dulieund
                            movc a,@a+dptr
                            mov p0,a
                            CLR p2.7
                            call t50ms
                            SETB p2.7
                            mov a,dulieunc
                            movc a,@a+dptr
                            mov p0,a
                            CLR p2.6
                            call t50ms
                            SETB p2.6
                            mov a,dulieutd
                            movc a,@a+dptr
                            mov p0,a
                            CLR p1.3
                            call t50ms ;===
                            SETB p1.3
                            mov a,dulieutc
                            movc a,@a+dptr
                            mov p0,a
                            CLR p1.2
                            call t50ms
                            SETB p1.2
                            mov a,demndd
                            movc a,@a+dptr
                            mov p0,a
                            CLR p1.7
                            call t50ms
                            SETB p1.7
                            mov a,demndc
                            movc a,@a+dptr
                            mov p0,a
                            CLR p1.6
                            call t50ms
                            SETB p1.6
                            mov a,#00h
                            movc a,@a+dptr
                            mov p0,a
                            CLR p1.5
                            call t50ms
                            SETB p1.5
                            mov a,#02h
                            movc a,@a+dptr
                            mov p0,a
                            CLR p1.4
                            call t50ms
                            SETB p1.4
                            ret
                            ;############################# Thoi gian quet led #######################
                            t50ms:
                            MOV R7,#8
                            LOOPD: MOV R6,#200
                            DJNZ R6,$
                            DJNZ R7,LOOPD
                            RET




                            ;########################## Chuyen BCD sang HEX ##########################
                            chuyenbcdsanghex:
                            mov a,tam2
                            anl a,#00001111b
                            mov 53h,a
                            mov a,tam2
                            anl a,#11110000b
                            swap a
                            mov 52h,a
                            mov b,52h
                            mov a,#0ah
                            mul ab
                            add a,53h
                            mov tam2,a
                            ret
                            ;########################## Chuyen sang HEX ##############################
                            chuyensanghex:
                            mov a,tam2
                            anl a,#00001111b
                            mov 53h,a
                            mov a,tam2
                            anl a,#11110000b
                            swap a
                            mov 52h,a
                            ret
                            ;########################## Chuyen sang BCD ##############################
                            chuyensangbcd:
                            tam equ 51h
                            tam1 equ 50h
                            mov tam,tam2
                            mov a,tam
                            mov b,#10
                            div ab
                            mov 52h,a
                            mov b,#10
                            mul ab 
                            mov tam1,a
                            mov a,tam
                            clr c
                            subb a,tam1
                            mov 53h,a
                            ret
                            ;################################################# ############################
                            WRITE_BYTE:
                            CLR SDA ;start bit
                            CLR SCL
                            MOV A,#BYTE_W ;send control byte
                            LCALL LOOP_BYTE
                            SETB SDA
                            SETB SCL
                            JB SDA,WRITE_BYTE ;loop until busy
                            CLR SCL
                            MOV A,ADD_LOW ;send address low
                            LCALL LOOP_BYTE
                            SETB SDA
                            SETB SCL
                            JB SDA,WRITE_BYTE ;loop until busy
                            CLR SCL
                            MOV A,DATA_DS ;send DATA
                            LCALL LOOP_BYTE
                            SETB SDA
                            SETB SCL
                            JB SDA,WRITE_BYTE ;loop until busy
                            CLR SDA
                            CLR SCL
                            SETB SCL ;stop bit
                            SETB SDA
                            RET
                            ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;
                            LOOP_BYTE:
                            PUSH 02H
                            MOV R2,#08H
                            LOOP_SEND:
                            RLC A
                            MOV SDA,C
                            SETB SCL
                            CLR SCL
                            DJNZ R2,LOOP_SEND
                            POP 02H
                            RET
                            ;###################### Du lieu quet led 7 doan ##############################
                            led7anode:
                            db 40h,79h,24h,30h,19h,12h,02h,78h,00h,10h
                            end

                            Comment


                            • #15
                              chắc các bạn đã làm thành công mạch đồng hồ rồi hay sao không thấy trao đổi nửa nhỉ?

                              Comment

                              Về tác giả

                              Collapse

                              hieuyeubich Tìm hiểu thêm về hieuyeubich

                              Bài viết mới nhất

                              Collapse

                              Đang tải...
                              X