Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LPC23xx.H> /* ???????? LPC23xx */
- #define STB 26 //Port1.26
- # define CLK 27 //Port1.27
- # define DIO 28 //Port1.28
- void delay(unsigned int count) {
- unsigned int i;
- for (i = 0; i < count; i++) {}
- }
- void tm1638_sendbyte(unsigned int x) {
- unsigned int i;
- IODIR1 |= (1 << DIO);
- for (i = 0; i < 8; i++) {
- IOCLR1 = (1 << CLK);
- delay(0xfff);
- if (x & 1) {
- IOSET1 = (1 << DIO);
- }
- else {
- IOCLR1 = (1 << DIO);
- }
- delay(0xfff); //????????
- x >>= 1;
- IOSET1 = (1 << CLK); //?????? CLK ????????????? ? 1
- delay(0x1fff);
- }
- }
- unsigned int tm1638_receivebyte() {
- unsigned int i;
- unsigned int x = 0;
- IODIR1 &= ~(1 << DIO);
- for (i = 0; i < 32; i++) {
- IOCLR1 = (1 << CLK);
- delay(0xfff);
- if (IOPIN1 & (1 << DIO)) {
- x |= (1 << i);
- }
- delay(0xfff);
- IOSET1 = (1 << CLK);
- delay(0x1fff);
- }
- return x;
- }
- void tm1638_sendcmd(unsigned int x) {
- IOSET1 = (1 << STB);
- IODIR1 = (1 << CLK) | (1 << DIO) | (1 << STB);
- IOCLR1 = (1 << STB);
- tm1638_sendbyte(x);
- }
- void tm1638_setadr(unsigned int adr) {
- tm1638_sendcmd(0xC0 | adr);
- }
- void tm1638_init() {
- unsigned int i;
- tm1638_sendcmd(0x88);
- tm1638_sendcmd(0x40);
- tm1638_setadr(0);
- for (i = 0; i <= 0xf; i++)
- tm1638_sendbyte(0);
- tm1638_sendcmd(0x44);
- }
- int main(void) {
- unsigned int n, i;
- tm1638_init();
- while (1) {
- for (n = 1; n <= 0xf; n += 2) {
- i = 1;
- while (i != 0) {
- // 0x46 means 0100 0110.
- //This command is used to read from keyboard register
- // using fixed-address mode
- tm1638_sendcmd(0x46);
- // Receiving current keyboard state
- i = tm1638_receivebyte();
- }
- // Setting the address of the LED Indication Register
- tm1638_setadr(n);
- // Sending a data to the register
- tm1638_sendbyte(n);
- delay(0xffff);
- // Turning of the LED
- tm1638_sendbyte(0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement