Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * zad1.c
- *
- * Created: 2013-04-17 11:49:22
- * Author: student
- */
- #include <avr/io.h>
- #include <lcd.h>
- #include <one_wire.h>
- #include <util/crc16.h>
- void iB_send_cmd(char cmd)
- {
- for (int i = 0; i < 8; i++)
- {
- iB_send_bit(cmd & 0x01);
- cmd >>=1;
- }
- }
- void iB_zapal(char led)
- {
- iB_wy |=_BV(led);
- }
- void iB_zgas(char led)
- {
- iB_wy &=~_BV(led);
- }
- iB_init()
- {
- // Diody: kier. WY
- iB_tx |=_BV(iB_RED) |_BV(iB_GREEN);
- // Linia 1-Wire: kier. WE (stan HIGH)
- iB_tx &=~_BV(iB_LINE);
- // Gasi diody
- iB_zgas(iB_RED);
- iB_zgas(iB_GREEN);
- // Linia 1-Wire: przygotowanie stanu LOW dla nadawania
- iB_wy &=~_BV(iB_LINE);
- }
- char iB_33h(char* Tab)
- {
- volatile char al;
- iB_send_cmd(0x33);
- char crc = 0;
- for (int i = 7; i > -1; i--) // 8 bajtów, od LSB
- {
- al = 0;
- for (int k = 0; k < 8; k++) // 8 bitów, od najmłodszego
- {
- al >>= 1;
- al |= iB_recv() << 7; // Bit na pozycji 7
- }
- crc = _crc_ibutton_update(crc, al);
- Tab[i] = al;
- }
- return(crc);
- }
- int main(void)
- {
- //_init_LCD();
- iB_init();
- //char tab[80];
- //_iB_33h(tab);
- while(1)
- {
- while(1)
- {
- iB_zapal(iB_RED);
- _delay_ms(500);
- if(iB_reset() != 0x01)
- break;
- iB_zgas(iB_RED);
- _delay_ms(500);
- if(iB_reset() != 0x01)
- break;
- }
- iB_zgas(iB_RED);
- iB_zapal(iB_GREEN);
- _delay_ms(3000);
- iB_zgas(iB_GREEN);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment